[PATCH] vdpa/mlx5: set_features should allow reset to zero

Subsystems: mellanox mlx5 vdpa driver, the rest, virtio core

STALE1721d

80 messages, 5 authors, 2021-12-17 · page 1 of 2 · open the first message on its own page

[PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Si-Wei Liu <hidden>
Date: 2021-02-19 11:56:47

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")
Signed-off-by: Si-Wei Liu <redacted>
---
 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)
-- 
1.8.3.1

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Eli Cohen <hidden>
Date: 2021-02-21 14:45:36

On Fri, Feb 19, 2021 at 06:54:58AM -0500, Si-Wei Liu wrote:
quoted hunk
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")
Signed-off-by: Si-Wei Liu <redacted>
---
 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;
-}
-
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 hunk
 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)
-- 
1.8.3.1

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-02-21 21:54:45

On Sun, Feb 21, 2021 at 04:44:37PM +0200, Eli Cohen wrote:
On Fri, Feb 19, 2021 at 06:54:58AM -0500, Si-Wei Liu wrote:
quoted
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")
Signed-off-by: Si-Wei Liu <redacted>
---
 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;
-}
-
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"?

Maybe we should call verify_min_features() from mlx5_vdpa_set_status()
just before attempting to call setup_driver().
quoted
 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)
-- 
1.8.3.1

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Jason Wang <hidden>
Date: 2021-02-22 04:16:22

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.
"

Do we really want to workaround this?

Thanks

quoted hunk
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 <redacted>
---
  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)

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Eli Cohen <hidden>
Date: 2021-02-22 06:06:43

On Sun, Feb 21, 2021 at 04:52:05PM -0500, Michael S. Tsirkin wrote:
On Sun, Feb 21, 2021 at 04:44:37PM +0200, Eli Cohen wrote:
quoted
On Fri, Feb 19, 2021 at 06:54:58AM -0500, Si-Wei Liu wrote:
quoted
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")
Signed-off-by: Si-Wei Liu <redacted>
---
 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;
-}
-
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"?
Actually I meant this driver/device does not support such cases.
quoted
Maybe we should call verify_min_features() from mlx5_vdpa_set_status()
just before attempting to call setup_driver().
quoted
 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)
-- 
1.8.3.1

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-02-22 07:36:55

On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote:
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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
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
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 <redacted>
---
  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)

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Si-Wei Liu <hidden>
Date: 2021-02-22 17:10:53


On 2/21/2021 8:14 PM, Jason Wang wrote:
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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?
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
Thanks

quoted
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 <redacted>
---
  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)

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Si-Wei Liu <hidden>
Date: 2021-02-23 01:13:46


On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote:
On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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
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?
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
quoted
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 <redacted>
---
   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)

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Jason Wang <hidden>
Date: 2021-02-23 02:05:08

On 2021/2/23 1:09 上午, Si-Wei Liu wrote:

On 2/21/2021 8:14 PM, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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?
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).

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

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

-Siwei
quoted
Thanks

quoted
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 <redacted>
---
  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)

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Jason Wang <hidden>
Date: 2021-02-23 02:05:55

On 2021/2/23 9:12 上午, Si-Wei Liu wrote:

On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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
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?
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
quoted
quoted
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 <redacted>
---
   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)

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-02-23 09:27:55

On Mon, Feb 22, 2021 at 09:09:28AM -0800, Si-Wei Liu wrote:

On 2/21/2021 8:14 PM, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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?
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.

-- 
MST

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-02-23 09:31:42

On Mon, Feb 22, 2021 at 08:05:26AM +0200, Eli Cohen wrote:
On Sun, Feb 21, 2021 at 04:52:05PM -0500, Michael S. Tsirkin wrote:
quoted
On Sun, Feb 21, 2021 at 04:44:37PM +0200, Eli Cohen wrote:
quoted
On Fri, Feb 19, 2021 at 06:54:58AM -0500, Si-Wei Liu wrote:
quoted
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")
Signed-off-by: Si-Wei Liu <redacted>
---
 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;
-}
-
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"?
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
quoted
Maybe we should call verify_min_features() from mlx5_vdpa_set_status()
just before attempting to call setup_driver().
quoted
 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)
-- 
1.8.3.1

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Jason Wang <hidden>
Date: 2021-02-23 09:49:58

On 2021/2/23 下午5:25, Michael S. Tsirkin wrote:
On Mon, Feb 22, 2021 at 09:09:28AM -0800, Si-Wei Liu wrote:
quoted
On 2/21/2021 8:14 PM, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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?
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);

I wonder why not simply fail here?

         }

         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".

So this probably need some clarification. "is set" is used many times in 
the spec that has different implications.

Thanks

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.

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Jason Wang <hidden>
Date: 2021-02-23 09:55:02

On 2021/2/23 下午5:26, Michael S. Tsirkin wrote:
On Mon, Feb 22, 2021 at 08:05:26AM +0200, Eli Cohen wrote:
quoted
On Sun, Feb 21, 2021 at 04:52:05PM -0500, Michael S. Tsirkin wrote:
quoted
On Sun, Feb 21, 2021 at 04:44:37PM +0200, Eli Cohen wrote:
quoted
On Fri, Feb 19, 2021 at 06:54:58AM -0500, Si-Wei Liu wrote:
quoted
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")
Signed-off-by: Si-Wei Liu<redacted>
---
  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;
-}
-
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"?
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


Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-02-23 10:01:09

On Tue, Feb 23, 2021 at 05:48:10PM +0800, Jason Wang wrote:
On 2021/2/23 下午5:26, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 08:05:26AM +0200, Eli Cohen wrote:
quoted
On Sun, Feb 21, 2021 at 04:52:05PM -0500, Michael S. Tsirkin wrote:
quoted
On Sun, Feb 21, 2021 at 04:44:37PM +0200, Eli Cohen wrote:
quoted
On Fri, Feb 19, 2021 at 06:54:58AM -0500, Si-Wei Liu wrote:
quoted
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")
Signed-off-by: Si-Wei Liu<redacted>
---
  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;
-}
-
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"?
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.

-- 
MST

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-02-23 10:04:26

On Tue, Feb 23, 2021 at 05:46:20PM +0800, Jason Wang wrote:
On 2021/2/23 下午5:25, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 09:09:28AM -0800, Si-Wei Liu wrote:
quoted
On 2/21/2021 8:14 PM, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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?
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);

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
         }

         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".

So this probably need some clarification. "is set" is used many times in the
spec that has different implications.

Thanks

quoted
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.

Re: [virtio-dev] Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Cornelia Huck <cohuck@redhat.com>
Date: 2021-02-23 10:07:21

On Tue, 23 Feb 2021 17:46:20 +0800
Jason Wang [off-list ref] wrote:
On 2021/2/23 下午5:25, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 09:09:28AM -0800, Si-Wei Liu wrote:  
quoted
On 2/21/2021 8:14 PM, Jason Wang wrote:  
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:  
quoted
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?  
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);  

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
         }

         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".  

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?

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Jason Wang <hidden>
Date: 2021-02-23 10:20:14

On 2021/2/23 6:01 下午, Michael S. Tsirkin wrote:
On Tue, Feb 23, 2021 at 05:46:20PM +0800, Jason Wang wrote:
quoted
On 2021/2/23 下午5:25, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 09:09:28AM -0800, Si-Wei Liu wrote:
quoted
On 2/21/2021 8:14 PM, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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?
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);
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.

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
quoted
          }

          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".
So this probably need some clarification. "is set" is used many times in the
spec that has different implications.

Thanks

quoted
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.

Re: [virtio-dev] Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Jason Wang <hidden>
Date: 2021-02-23 10:33:36

On 2021/2/23 6:04 下午, Cornelia Huck wrote:
On Tue, 23 Feb 2021 17:46:20 +0800
Jason Wang [off-list ref] wrote:
quoted
On 2021/2/23 下午5:25, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 09:09:28AM -0800, Si-Wei Liu wrote:
quoted
On 2/21/2021 8:14 PM, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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?
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);
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
quoted
          }

          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".
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.


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?

  (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.

Should we add a wording clarification to the spec?

I think so.

Thanks

Re: [virtio-dev] Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Cornelia Huck <cohuck@redhat.com>
Date: 2021-02-23 11:01:32

On Tue, 23 Feb 2021 18:31:07 +0800
Jason Wang [off-list ref] wrote:
On 2021/2/23 6:04 下午, Cornelia Huck wrote:
quoted
On Tue, 23 Feb 2021 17:46:20 +0800
Jason Wang [off-list ref] wrote:
 
quoted
On 2021/2/23 下午5:25, Michael S. Tsirkin wrote:  
quoted
On Mon, Feb 22, 2021 at 09:09:28AM -0800, Si-Wei Liu wrote:  
quoted
On 2/21/2021 8:14 PM, Jason Wang wrote:  
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:  
quoted
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?  
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);  
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
 
quoted
          }

          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".  
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
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
  (This is a bit fuzzy for legacy mode.)
...because legacy does not have FEATURES_OK.
  

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.)
 
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
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."

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-02-23 12:28:48

On Fri, Feb 19, 2021 at 06:54:58AM -0500, 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. 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")
isn't this more

    vdpa: make sure set_features is invoked for legacy

Signed-off-by: Si-Wei Liu <redacted>
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 hunk
---
 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;
Let's just set VIRTIO_F_ACCESS_PLATFORM in core?
Then we don't need to hack mlx5 ...

quoted hunk
@@ -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)
-- 
1.8.3.1

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-02-23 13:28:26

On Tue, Feb 23, 2021 at 10:03:57AM +0800, Jason Wang wrote:
On 2021/2/23 9:12 上午, Si-Wei Liu wrote:
quoted

On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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
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?
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
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
quoted
quoted
quoted
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 <redacted>
---
   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)

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Si-Wei Liu <hidden>
Date: 2021-02-23 19:37:52


On 2/23/2021 5:26 AM, Michael S. Tsirkin wrote:
On Tue, Feb 23, 2021 at 10:03:57AM +0800, Jason Wang wrote:
quoted
On 2021/2/23 9:12 上午, Si-Wei Liu wrote:
quoted
On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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
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?
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
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
quoted
quoted
quoted
quoted
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 <redacted>
---
    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)

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Jason Wang <hidden>
Date: 2021-02-24 03:21:44

On 2021/2/24 3:35 上午, Si-Wei Liu wrote:

On 2/23/2021 5:26 AM, Michael S. Tsirkin wrote:
quoted
On Tue, Feb 23, 2021 at 10:03:57AM +0800, Jason Wang wrote:
quoted
On 2021/2/23 9:12 上午, Si-Wei Liu wrote:
quoted
On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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
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?
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
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

-Siwie
quoted
quoted
quoted
quoted
quoted
quoted
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 <redacted>
---
    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)

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-02-24 05:06:13

On Tue, Feb 23, 2021 at 11:35:57AM -0800, Si-Wei Liu wrote:

On 2/23/2021 5:26 AM, Michael S. Tsirkin wrote:
quoted
On Tue, Feb 23, 2021 at 10:03:57AM +0800, Jason Wang wrote:
quoted
On 2021/2/23 9:12 上午, Si-Wei Liu wrote:
quoted
On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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
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?
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
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
quoted
quoted
quoted
quoted
quoted
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 <redacted>
---
    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)

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-02-24 05:19:58

On Wed, Feb 24, 2021 at 11:20:01AM +0800, Jason Wang wrote:
On 2021/2/24 3:35 上午, Si-Wei Liu wrote:
quoted

On 2/23/2021 5:26 AM, Michael S. Tsirkin wrote:
quoted
On Tue, Feb 23, 2021 at 10:03:57AM +0800, Jason Wang wrote:
quoted
On 2021/2/23 9:12 上午, Si-Wei Liu wrote:
quoted
On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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
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?
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
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
Well mlx5 has some code to handle legacy guests ...
Eli, could you comment? Is that support unused right now?

quoted
-Siwie
quoted
quoted
quoted
quoted
quoted
quoted
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 <redacted>
---
    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)

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Jason Wang <hidden>
Date: 2021-02-24 06:04:23

On 2021/2/24 1:17 下午, Michael S. Tsirkin wrote:
On Wed, Feb 24, 2021 at 11:20:01AM +0800, Jason Wang wrote:
quoted
On 2021/2/24 3:35 上午, Si-Wei Liu wrote:
quoted
On 2/23/2021 5:26 AM, Michael S. Tsirkin wrote:
quoted
On Tue, Feb 23, 2021 at 10:03:57AM +0800, Jason Wang wrote:
quoted
On 2021/2/23 9:12 上午, Si-Wei Liu wrote:
quoted
On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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
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?
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
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
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

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

quoted
quoted
-Siwie
quoted
quoted
quoted
quoted
quoted
quoted
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 <redacted>
---
     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)

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Jason Wang <hidden>
Date: 2021-02-24 06:06:44

On 2021/2/24 1:04 下午, Michael S. Tsirkin wrote:
On Tue, Feb 23, 2021 at 11:35:57AM -0800, Si-Wei Liu wrote:
quoted
On 2/23/2021 5:26 AM, Michael S. Tsirkin wrote:
quoted
On Tue, Feb 23, 2021 at 10:03:57AM +0800, Jason Wang wrote:
quoted
On 2021/2/23 9:12 上午, Si-Wei Liu wrote:
quoted
On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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
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?
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
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 :(

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
quoted
quoted
quoted
quoted
quoted
quoted
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 <redacted>
---
     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)

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Eli Cohen <hidden>
Date: 2021-02-24 06:46:31

On Wed, Feb 24, 2021 at 12:17:58AM -0500, Michael S. Tsirkin wrote:
On Wed, Feb 24, 2021 at 11:20:01AM +0800, Jason Wang wrote:
quoted
On 2021/2/24 3:35 上午, Si-Wei Liu wrote:
quoted

On 2/23/2021 5:26 AM, Michael S. Tsirkin wrote:
quoted
On Tue, Feb 23, 2021 at 10:03:57AM +0800, Jason Wang wrote:
quoted
On 2021/2/23 9:12 上午, Si-Wei Liu wrote:
quoted
On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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
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?
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
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
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
quoted
-Siwie
quoted
quoted
quoted
quoted
quoted
quoted
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 <redacted>
---
    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)

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-02-24 06:48:27

On Wed, Feb 24, 2021 at 02:04:36PM +0800, Jason Wang wrote:
On 2021/2/24 1:04 下午, Michael S. Tsirkin wrote:
quoted
On Tue, Feb 23, 2021 at 11:35:57AM -0800, Si-Wei Liu wrote:
quoted
On 2/23/2021 5:26 AM, Michael S. Tsirkin wrote:
quoted
On Tue, Feb 23, 2021 at 10:03:57AM +0800, Jason Wang wrote:
quoted
On 2021/2/23 9:12 上午, Si-Wei Liu wrote:
quoted
On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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
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?
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
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 :(

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.
And I wonder what will hapeen if we just revert the set_features(0)?

Thanks

quoted
quoted
quoted
quoted
quoted
quoted
quoted
quoted
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 <redacted>
---
     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)

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-02-24 06:50:02

On Wed, Feb 24, 2021 at 08:45:20AM +0200, Eli Cohen wrote:
On Wed, Feb 24, 2021 at 12:17:58AM -0500, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 11:20:01AM +0800, Jason Wang wrote:
quoted
On 2021/2/24 3:35 上午, Si-Wei Liu wrote:
quoted

On 2/23/2021 5:26 AM, Michael S. Tsirkin wrote:
quoted
On Tue, Feb 23, 2021 at 10:03:57AM +0800, Jason Wang wrote:
quoted
On 2021/2/23 9:12 上午, Si-Wei Liu wrote:
quoted
On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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
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?
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
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
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
quoted
quoted
-Siwie
quoted
quoted
quoted
quoted
quoted
quoted
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 <redacted>
---
    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)

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Jason Wang <hidden>
Date: 2021-02-24 06:55:20

On 2021/2/24 2:46 下午, Michael S. Tsirkin wrote:
On Wed, Feb 24, 2021 at 02:04:36PM +0800, Jason Wang wrote:
quoted
On 2021/2/24 1:04 下午, Michael S. Tsirkin wrote:
quoted
On Tue, Feb 23, 2021 at 11:35:57AM -0800, Si-Wei Liu wrote:
quoted
On 2/23/2021 5:26 AM, Michael S. Tsirkin wrote:
quoted
On Tue, Feb 23, 2021 at 10:03:57AM +0800, Jason Wang wrote:
quoted
On 2021/2/23 9:12 上午, Si-Wei Liu wrote:
quoted
On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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
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?
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
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 :(
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
And I wonder what will hapeen if we just revert the set_features(0)?

Thanks

quoted
quoted
quoted
quoted
quoted
quoted
quoted
quoted
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 <redacted>
---
      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)

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Jason Wang <hidden>
Date: 2021-02-24 06:57:41

On 2021/2/24 2:47 下午, Michael S. Tsirkin wrote:
On Wed, Feb 24, 2021 at 08:45:20AM +0200, Eli Cohen wrote:
quoted
On Wed, Feb 24, 2021 at 12:17:58AM -0500, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 11:20:01AM +0800, Jason Wang wrote:
quoted
On 2021/2/24 3:35 上午, Si-Wei Liu wrote:
quoted
On 2/23/2021 5:26 AM, Michael S. Tsirkin wrote:
quoted
On Tue, Feb 23, 2021 at 10:03:57AM +0800, Jason Wang wrote:
quoted
On 2021/2/23 9:12 上午, Si-Wei Liu wrote:
quoted
On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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
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?
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
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
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
quoted
quoted
quoted
-Siwie
quoted
quoted
quoted
quoted
quoted
quoted
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 <redacted>
---
     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)

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-02-24 07:14:50

On Wed, Feb 24, 2021 at 02:55:13PM +0800, Jason Wang wrote:
On 2021/2/24 2:47 下午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 08:45:20AM +0200, Eli Cohen wrote:
quoted
On Wed, Feb 24, 2021 at 12:17:58AM -0500, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 11:20:01AM +0800, Jason Wang wrote:
quoted
On 2021/2/24 3:35 上午, Si-Wei Liu wrote:
quoted
On 2/23/2021 5:26 AM, Michael S. Tsirkin wrote:
quoted
On Tue, Feb 23, 2021 at 10:03:57AM +0800, Jason Wang wrote:
quoted
On 2021/2/23 9:12 上午, Si-Wei Liu wrote:
quoted
On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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
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?
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
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
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
Legacy mode description is the spec is non-normative. As such as long as
guests work, they work ;)
quoted
quoted
quoted
quoted
quoted
-Siwie
quoted
quoted
quoted
quoted
quoted
quoted
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 <redacted>
---
     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)

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Eli Cohen <hidden>
Date: 2021-02-24 07:19:30

On Wed, Feb 24, 2021 at 02:55:13PM +0800, Jason Wang wrote:
On 2021/2/24 2:47 下午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 08:45:20AM +0200, Eli Cohen wrote:
quoted
On Wed, Feb 24, 2021 at 12:17:58AM -0500, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 11:20:01AM +0800, Jason Wang wrote:
quoted
On 2021/2/24 3:35 上午, Si-Wei Liu wrote:
quoted
On 2/23/2021 5:26 AM, Michael S. Tsirkin wrote:
quoted
On Tue, Feb 23, 2021 at 10:03:57AM +0800, Jason Wang wrote:
quoted
On 2021/2/23 9:12 上午, Si-Wei Liu wrote:
quoted
On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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
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?
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
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
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?
I am checking this with some folks here.
Thanks

quoted
quoted
quoted
quoted
quoted
-Siwie
quoted
quoted
quoted
quoted
quoted
quoted
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 <redacted>
---
     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)

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-02-24 07:20:25

On Wed, Feb 24, 2021 at 02:53:08PM +0800, Jason Wang wrote:
On 2021/2/24 2:46 下午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 02:04:36PM +0800, Jason Wang wrote:
quoted
On 2021/2/24 1:04 下午, Michael S. Tsirkin wrote:
quoted
On Tue, Feb 23, 2021 at 11:35:57AM -0800, Si-Wei Liu wrote:
quoted
On 2/23/2021 5:26 AM, Michael S. Tsirkin wrote:
quoted
On Tue, Feb 23, 2021 at 10:03:57AM +0800, Jason Wang wrote:
quoted
On 2021/2/23 9:12 上午, Si-Wei Liu wrote:
quoted
On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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
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?
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
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 :(
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


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
quoted
And I wonder what will hapeen if we just revert the set_features(0)?

Thanks

quoted
quoted
quoted
quoted
quoted
quoted
quoted
quoted
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 <redacted>
---
      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)

Re: [virtio-dev] Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Jason Wang <hidden>
Date: 2021-02-24 09:31:18

On 2021/2/23 6:58 下午, Cornelia Huck wrote:
On Tue, 23 Feb 2021 18:31:07 +0800
Jason Wang [off-list ref] wrote:
quoted
On 2021/2/23 6:04 下午, Cornelia Huck wrote:
quoted
On Tue, 23 Feb 2021 17:46:20 +0800
Jason Wang [off-list ref] wrote:
  
quoted
On 2021/2/23 下午5:25, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 09:09:28AM -0800, Si-Wei Liu wrote:
quoted
On 2/21/2021 8:14 PM, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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?
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);
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
  
quoted
           }

           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".
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
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
quoted
   (This is a bit fuzzy for legacy mode.)
...because legacy does not have FEATURES_OK.
   
quoted
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.)

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
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.

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
quoted
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,

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;
};

  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


Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Jason Wang <hidden>
Date: 2021-02-24 09:45:39

On 2021/2/23 6:17 下午, Jason Wang wrote:
On 2021/2/23 6:01 下午, Michael S. Tsirkin wrote:
quoted
On Tue, Feb 23, 2021 at 05:46:20PM +0800, Jason Wang wrote:
quoted
On 2021/2/23 下午5:25, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 09:09:28AM -0800, Si-Wei Liu wrote:
quoted
On 2/21/2021 8:14 PM, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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?
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);
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.

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

In that case, the driver can not live either. Clearing MTU won't help 
here.

Thanks

quoted
quoted
quoted
          }

          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".
So this probably need some clarification. "is set" is used many 
times in the
spec that has different implications.

Thanks

quoted
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.

Re: [virtio-dev] Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Cornelia Huck <cohuck@redhat.com>
Date: 2021-02-24 11:16:29

On Wed, 24 Feb 2021 17:29:07 +0800
Jason Wang [off-list ref] wrote:
On 2021/2/23 6:58 下午, Cornelia Huck wrote:
quoted
On Tue, 23 Feb 2021 18:31:07 +0800
Jason Wang [off-list ref] wrote:
 
quoted
On 2021/2/23 6:04 下午, Cornelia Huck wrote:  
quoted
On Tue, 23 Feb 2021 17:46:20 +0800
Jason Wang [off-list ref] wrote:
    
quoted
On 2021/2/23 下午5:25, Michael S. Tsirkin wrote:  
quoted
On Mon, Feb 22, 2021 at 09:09:28AM -0800, Si-Wei Liu wrote:  
quoted
On 2/21/2021 8:14 PM, Jason Wang wrote:  
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:  
quoted
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?  
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);  
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
    
quoted
           }

           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".  
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
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
 
quoted
 
quoted
   (This is a bit fuzzy for legacy mode.)  
...because legacy does not have FEATURES_OK.
     
quoted
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.)  

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.
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
    
quoted
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
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
 
quoted
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,  

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
  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"?

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Eli Cohen <hidden>
Date: 2021-02-24 12:42:18

On Wed, Feb 24, 2021 at 02:12:01AM -0500, Michael S. Tsirkin wrote:
On Wed, Feb 24, 2021 at 02:55:13PM +0800, Jason Wang wrote:
quoted
On 2021/2/24 2:47 下午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 08:45:20AM +0200, Eli Cohen wrote:
quoted
On Wed, Feb 24, 2021 at 12:17:58AM -0500, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 11:20:01AM +0800, Jason Wang wrote:
quoted
On 2021/2/24 3:35 上午, Si-Wei Liu wrote:
quoted
On 2/23/2021 5:26 AM, Michael S. Tsirkin wrote:
quoted
On Tue, Feb 23, 2021 at 10:03:57AM +0800, Jason Wang wrote:
quoted
On 2021/2/23 9:12 上午, Si-Wei Liu wrote:
quoted
On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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
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?
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
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
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 ;)
Guys sorry, I checked again, the firmware capability is set and so is
VIRTIO_F_VERSION_1.
quoted
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
quoted
quoted
quoted
quoted
quoted
-Siwie
quoted
quoted
quoted
quoted
quoted
quoted
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 <redacted>
---
     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)

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Si-Wei Liu <hidden>
Date: 2021-02-24 18:25:59


On 2/23/2021 9:04 PM, Michael S. Tsirkin wrote:
On Tue, Feb 23, 2021 at 11:35:57AM -0800, Si-Wei Liu wrote:
quoted
On 2/23/2021 5:26 AM, Michael S. Tsirkin wrote:
quoted
On Tue, Feb 23, 2021 at 10:03:57AM +0800, Jason Wang wrote:
quoted
On 2021/2/23 9:12 上午, Si-Wei Liu wrote:
quoted
On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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
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?
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
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 :(
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
quoted
quoted
quoted
quoted
quoted
quoted
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 <redacted>
---
     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)

Re: [virtio-dev] Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Jason Wang <hidden>
Date: 2021-02-25 04:38:22

On 2021/2/24 7:12 下午, Cornelia Huck wrote:
On Wed, 24 Feb 2021 17:29:07 +0800
Jason Wang [off-list ref] wrote:
quoted
On 2021/2/23 6:58 下午, Cornelia Huck wrote:
quoted
On Tue, 23 Feb 2021 18:31:07 +0800
Jason Wang [off-list ref] wrote:
  
quoted
On 2021/2/23 6:04 下午, Cornelia Huck wrote:
quoted
On Tue, 23 Feb 2021 17:46:20 +0800
Jason Wang [off-list ref] wrote:
     
quoted
On 2021/2/23 下午5:25, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 09:09:28AM -0800, Si-Wei Liu wrote:
quoted
On 2/21/2021 8:14 PM, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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?
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);
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
     
quoted
            }

            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".
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
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
  
quoted
  
quoted
    (This is a bit fuzzy for legacy mode.)
...because legacy does not have FEATURES_OK.
      
quoted
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.)
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
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
quoted
     
quoted
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
quoted
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
  
quoted
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,
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.

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
quoted
   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

Re: [virtio-dev] Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Cornelia Huck <cohuck@redhat.com>
Date: 2021-02-25 13:29:49

On Thu, 25 Feb 2021 12:36:07 +0800
Jason Wang [off-list ref] wrote:
On 2021/2/24 7:12 下午, Cornelia Huck wrote:
quoted
On Wed, 24 Feb 2021 17:29:07 +0800
Jason Wang [off-list ref] wrote:
 
quoted
On 2021/2/23 6:58 下午, Cornelia Huck wrote:  
quoted
On Tue, 23 Feb 2021 18:31:07 +0800
Jason Wang [off-list ref] wrote:
quoted
quoted
quoted
quoted
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.)  
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
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);
         }
Ouch, you're right. The virtio_cread accessors all operate on offsets
into a structure, it's just more obvious here.
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
 
quoted
 
quoted
       
quoted
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
 
quoted
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
    
quoted
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,  
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.  

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
 
quoted
quoted
   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).
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.

Re: [virtio-dev] Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-02-25 18:55:29

On Thu, Feb 25, 2021 at 12:36:07PM +0800, Jason Wang wrote:
On 2021/2/24 7:12 下午, Cornelia Huck wrote:
quoted
On Wed, 24 Feb 2021 17:29:07 +0800
Jason Wang [off-list ref] wrote:
quoted
On 2021/2/23 6:58 下午, Cornelia Huck wrote:
quoted
On Tue, 23 Feb 2021 18:31:07 +0800
Jason Wang [off-list ref] wrote:
quoted
On 2021/2/23 6:04 下午, Cornelia Huck wrote:
quoted
On Tue, 23 Feb 2021 17:46:20 +0800
Jason Wang [off-list ref] wrote:
quoted
On 2021/2/23 下午5:25, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 09:09:28AM -0800, Si-Wei Liu wrote:
quoted
On 2/21/2021 8:14 PM, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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?
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);
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
quoted
            }

            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".
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
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
quoted
quoted
    (This is a bit fuzzy for legacy mode.)
...because legacy does not have FEATURES_OK.
quoted
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.)
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
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.
Confused. What is wrong with the above? It never reads the
field unless the feature has been offered by device.

quoted
quoted
quoted
quoted
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
quoted
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
quoted
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,
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.

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
quoted
quoted
   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

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Si-Wei Liu <hidden>
Date: 2021-02-26 00:58:05

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

On 2/24/2021 10:24 AM, Si-Wei Liu wrote:
quoted
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

Re: [virtio-dev] Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Jason Wang <hidden>
Date: 2021-02-26 08:21:31

On 2021/2/26 2:53 上午, Michael S. Tsirkin wrote:
On Thu, Feb 25, 2021 at 12:36:07PM +0800, Jason Wang wrote:
quoted
On 2021/2/24 7:12 下午, Cornelia Huck wrote:
quoted
On Wed, 24 Feb 2021 17:29:07 +0800
Jason Wang [off-list ref] wrote:
quoted
On 2021/2/23 6:58 下午, Cornelia Huck wrote:
quoted
On Tue, 23 Feb 2021 18:31:07 +0800
Jason Wang [off-list ref] wrote:
quoted
On 2021/2/23 6:04 下午, Cornelia Huck wrote:
quoted
On Tue, 23 Feb 2021 17:46:20 +0800
Jason Wang [off-list ref] wrote:
quoted
On 2021/2/23 下午5:25, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 09:09:28AM -0800, Si-Wei Liu wrote:
quoted
On 2/21/2021 8:14 PM, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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?
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);
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
quoted
             }

             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".
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
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
quoted
quoted
     (This is a bit fuzzy for legacy mode.)
...because legacy does not have FEATURES_OK.
quoted
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.)
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
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.
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
quoted
quoted
quoted
quoted
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
quoted
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
quoted
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,
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.
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
quoted
quoted
    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

Re: [virtio-dev] Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-02-28 21:27:06

On Fri, Feb 26, 2021 at 04:19:16PM +0800, Jason Wang wrote:
On 2021/2/26 2:53 上午, Michael S. Tsirkin wrote:
quoted
On Thu, Feb 25, 2021 at 12:36:07PM +0800, Jason Wang wrote:
quoted
On 2021/2/24 7:12 下午, Cornelia Huck wrote:
quoted
On Wed, 24 Feb 2021 17:29:07 +0800
Jason Wang [off-list ref] wrote:
quoted
On 2021/2/23 6:58 下午, Cornelia Huck wrote:
quoted
On Tue, 23 Feb 2021 18:31:07 +0800
Jason Wang [off-list ref] wrote:
quoted
On 2021/2/23 6:04 下午, Cornelia Huck wrote:
quoted
On Tue, 23 Feb 2021 17:46:20 +0800
Jason Wang [off-list ref] wrote:
quoted
On 2021/2/23 下午5:25, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 09:09:28AM -0800, Si-Wei Liu wrote:
quoted
On 2/21/2021 8:14 PM, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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?
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);
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
quoted
             }

             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".
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
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
quoted
quoted
     (This is a bit fuzzy for legacy mode.)
...because legacy does not have FEATURES_OK.
quoted
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.)
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
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.
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
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
quoted
quoted
quoted
quoted
quoted
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
quoted
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
quoted
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,
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.
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
quoted
quoted
    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

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-02-28 21:29:27

On Thu, Feb 25, 2021 at 04:56:42PM -0800, Si-Wei Liu wrote:
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

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.

-- 
MST

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-02-28 21:30:51

On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:

On 2/23/2021 9:04 PM, Michael S. Tsirkin wrote:
quoted
On Tue, Feb 23, 2021 at 11:35:57AM -0800, Si-Wei Liu wrote:
quoted
On 2/23/2021 5:26 AM, Michael S. Tsirkin wrote:
quoted
On Tue, Feb 23, 2021 at 10:03:57AM +0800, Jason Wang wrote:
quoted
On 2021/2/23 9:12 上午, Si-Wei Liu wrote:
quoted
On 2/21/2021 11:34 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 12:14:17PM +0800, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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
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?
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
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 :(
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.
If it's optional, suppose the kernel may need it only when it becomes
necessary?

Thanks,
-Siwei

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-02-28 21:36:49

On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
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 ...

-- 
MST

Re: [virtio-dev] Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Jason Wang <hidden>
Date: 2021-03-01 03:53:28

On 2021/3/1 5:25 上午, Michael S. Tsirkin wrote:
On Fri, Feb 26, 2021 at 04:19:16PM +0800, Jason Wang wrote:
quoted
On 2021/2/26 2:53 上午, Michael S. Tsirkin wrote:
quoted
On Thu, Feb 25, 2021 at 12:36:07PM +0800, Jason Wang wrote:
quoted
On 2021/2/24 7:12 下午, Cornelia Huck wrote:
quoted
On Wed, 24 Feb 2021 17:29:07 +0800
Jason Wang [off-list ref] wrote:
quoted
On 2021/2/23 6:58 下午, Cornelia Huck wrote:
quoted
On Tue, 23 Feb 2021 18:31:07 +0800
Jason Wang [off-list ref] wrote:
quoted
On 2021/2/23 6:04 下午, Cornelia Huck wrote:
quoted
On Tue, 23 Feb 2021 17:46:20 +0800
Jason Wang [off-list ref] wrote:
quoted
On 2021/2/23 下午5:25, Michael S. Tsirkin wrote:
quoted
On Mon, Feb 22, 2021 at 09:09:28AM -0800, Si-Wei Liu wrote:
quoted
On 2/21/2021 8:14 PM, Jason Wang wrote:
quoted
On 2021/2/19 7:54 下午, Si-Wei Liu wrote:
quoted
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?
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);
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
quoted
              }

              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".
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
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
quoted
quoted
      (This is a bit fuzzy for legacy mode.)
...because legacy does not have FEATURES_OK.
quoted
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.)
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
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.
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
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
quoted
quoted
quoted
quoted
quoted
quoted
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
quoted
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
quoted
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,
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.
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
quoted
quoted
     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

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Jason Wang <hidden>
Date: 2021-03-01 03:59:15

On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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


Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Si-Wei Liu <hidden>
Date: 2021-03-01 23:56:01


On 2/28/2021 1:27 PM, Michael S. Tsirkin wrote:
On Thu, Feb 25, 2021 at 04:56:42PM -0800, Si-Wei Liu wrote:
quoted
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
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

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-03-02 10:11:10

On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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. 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.


-- 
MST

Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Jason Wang <hidden>
Date: 2021-03-02 11:22:08

On 2021/3/2 5:47 下午, Michael S. Tsirkin wrote:
On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
quoted
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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


Re: [virtio-dev] Re: [PATCH] vdpa/mlx5: set_features should allow reset to zero

From: Cornelia Huck <cohuck@redhat.com>
Date: 2021-03-02 13:02:40

On Mon, 1 Mar 2021 11:51:08 +0800
Jason Wang [off-list ref] wrote:
On 2021/3/1 5:25 上午, Michael S. Tsirkin wrote:
quoted
On Fri, Feb 26, 2021 at 04:19:16PM +0800, Jason Wang wrote:  
quoted
On 2021/2/26 2:53 上午, Michael S. Tsirkin wrote:  
quoted
quoted
quoted
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  
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.
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.

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

From: Si-Wei Liu <hidden>
Date: 2021-12-11 01:44:31

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

On 3/2/2021 2:53 AM, Jason Wang wrote:
On 2021/3/2 5:47 下午, Michael S. Tsirkin wrote:
quoted
On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
quoted
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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
  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

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

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-12-12 09:26:17

On Fri, Dec 10, 2021 at 05:44:15PM -0800, Si-Wei Liu wrote:
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?
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
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 ...

On 3/2/2021 2:53 AM, Jason Wang wrote:
quoted
On 2021/3/2 5:47 下午, Michael S. Tsirkin wrote:
quoted
On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
quoted
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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
  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

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

From: Jason Wang <hidden>
Date: 2021-12-13 03:03:43

On Sun, Dec 12, 2021 at 5:26 PM Michael S. Tsirkin [off-list ref] wrote:
On Fri, Dec 10, 2021 at 05:44:15PM -0800, Si-Wei Liu wrote:
quoted
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?
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
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
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
On 3/2/2021 2:53 AM, Jason Wang wrote:
quoted
On 2021/3/2 5:47 下午, Michael S. Tsirkin wrote:
quoted
On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
quoted
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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
  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

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

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-12-13 08:06:58

On Mon, Dec 13, 2021 at 11:02:39AM +0800, Jason Wang wrote:
On Sun, Dec 12, 2021 at 5:26 PM Michael S. Tsirkin [off-list ref] wrote:
quoted
On Fri, Dec 10, 2021 at 05:44:15PM -0800, Si-Wei Liu wrote:
quoted
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?
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
Limiting things to x86 will likely address most issues though, won't it?
quoted
quoted
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
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
On 3/2/2021 2:53 AM, Jason Wang wrote:
quoted
On 2021/3/2 5:47 下午, Michael S. Tsirkin wrote:
quoted
On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
quoted
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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
  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

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

From: Jason Wang <hidden>
Date: 2021-12-13 08:57:57

On Mon, Dec 13, 2021 at 4:07 PM Michael S. Tsirkin [off-list ref] wrote:
On Mon, Dec 13, 2021 at 11:02:39AM +0800, Jason Wang wrote:
quoted
On Sun, Dec 12, 2021 at 5:26 PM Michael S. Tsirkin [off-list ref] wrote:
quoted
On Fri, Dec 10, 2021 at 05:44:15PM -0800, Si-Wei Liu wrote:
quoted
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?
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
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
quoted
quoted
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
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
On 3/2/2021 2:53 AM, Jason Wang wrote:
quoted
On 2021/3/2 5:47 下午, Michael S. Tsirkin wrote:
quoted
On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
quoted
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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
  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

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

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-12-13 10:43:06

On Mon, Dec 13, 2021 at 04:57:38PM +0800, Jason Wang wrote:
On Mon, Dec 13, 2021 at 4:07 PM Michael S. Tsirkin [off-list ref] wrote:
quoted
On Mon, Dec 13, 2021 at 11:02:39AM +0800, Jason Wang wrote:
quoted
On Sun, Dec 12, 2021 at 5:26 PM Michael S. Tsirkin [off-list ref] wrote:
quoted
On Fri, Dec 10, 2021 at 05:44:15PM -0800, Si-Wei Liu wrote:
quoted
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?
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
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.
The driver ok thing is mostly an issue for block where it
expects to access the disk directly during probe.
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
quoted
quoted
quoted
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
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
On 3/2/2021 2:53 AM, Jason Wang wrote:
quoted
On 2021/3/2 5:47 下午, Michael S. Tsirkin wrote:
quoted
On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
quoted
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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
  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

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

From: Si-Wei Liu <hidden>
Date: 2021-12-14 01:14:18


On 12/12/2021 7:02 PM, Jason Wang wrote:
On Sun, Dec 12, 2021 at 5:26 PM Michael S. Tsirkin [off-list ref] wrote:
quoted
On Fri, Dec 10, 2021 at 05:44:15PM -0800, Si-Wei Liu wrote:
quoted
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.
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
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.
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

Thanks
quoted
quoted
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
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
On 3/2/2021 2:53 AM, Jason Wang wrote:
quoted
On 2021/3/2 5:47 下午, Michael S. Tsirkin wrote:
quoted
On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
quoted
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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
   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

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

From: Si-Wei Liu <hidden>
Date: 2021-12-14 02:00:08


On 12/12/2021 1:26 AM, Michael S. Tsirkin wrote:
On Fri, Dec 10, 2021 at 05:44:15PM -0800, Si-Wei Liu wrote:
quoted
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?
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
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
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
On 3/2/2021 2:53 AM, Jason Wang wrote:
quoted
On 2021/3/2 5:47 下午, Michael S. Tsirkin wrote:
quoted
On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
quoted
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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
   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

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

From: Jason Wang <hidden>
Date: 2021-12-14 03:02:16

On Tue, Dec 14, 2021 at 10:00 AM Si-Wei Liu [off-list ref] wrote:


On 12/12/2021 1:26 AM, Michael S. Tsirkin wrote:
quoted
On Fri, Dec 10, 2021 at 05:44:15PM -0800, Si-Wei Liu wrote:
quoted
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?
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.
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
quoted
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
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
Or are you suggesting
limit to legacy only at the time of vdpa creation would simplify the
implementation a lot?

Thanks,
-Siwei
quoted
quoted
On 3/2/2021 2:53 AM, Jason Wang wrote:
quoted
On 2021/3/2 5:47 下午, Michael S. Tsirkin wrote:
quoted
On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
quoted
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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
   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

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

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-12-14 05:06:19

On Mon, Dec 13, 2021 at 05:59:45PM -0800, Si-Wei Liu wrote:

On 12/12/2021 1:26 AM, Michael S. Tsirkin wrote:
quoted
On Fri, Dec 10, 2021 at 05:44:15PM -0800, Si-Wei Liu wrote:
quoted
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?
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?
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
quoted
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
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

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
quoted
On 3/2/2021 2:53 AM, Jason Wang wrote:
quoted
On 2021/3/2 5:47 下午, Michael S. Tsirkin wrote:
quoted
On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
quoted
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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
   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

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

From: Si-Wei Liu <hidden>
Date: 2021-12-15 01:05:59


On 12/13/2021 9:06 PM, Michael S. Tsirkin wrote:
On Mon, Dec 13, 2021 at 05:59:45PM -0800, Si-Wei Liu wrote:
quoted
On 12/12/2021 1:26 AM, Michael S. Tsirkin wrote:
quoted
On Fri, Dec 10, 2021 at 05:44:15PM -0800, Si-Wei Liu wrote:
quoted
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?
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
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
quoted
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
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
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
quoted
quoted
On 3/2/2021 2:53 AM, Jason Wang wrote:
quoted
On 2021/3/2 5:47 下午, Michael S. Tsirkin wrote:
quoted
On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
quoted
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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
    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

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

From: Jason Wang <hidden>
Date: 2021-12-15 02:06:50

On Wed, Dec 15, 2021 at 9:05 AM Si-Wei Liu [off-list ref] wrote:


On 12/13/2021 9:06 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Dec 13, 2021 at 05:59:45PM -0800, Si-Wei Liu wrote:
quoted
On 12/12/2021 1:26 AM, Michael S. Tsirkin wrote:
quoted
On Fri, Dec 10, 2021 at 05:44:15PM -0800, Si-Wei Liu wrote:
quoted
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?
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.
It's more than just config space, most devices have headers before the buffer.
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
quoted
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
quoted
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
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
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.
Michael may think differently but I think doing this in Qemu is much easier.

Thanks


Meanwhile, I'll check internally to see if a legacy only model would
work. Thanks.

Thanks,
-Siwei

quoted
quoted
quoted
quoted
On 3/2/2021 2:53 AM, Jason Wang wrote:
quoted
On 2021/3/2 5:47 下午, Michael S. Tsirkin wrote:
quoted
On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
quoted
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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
    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

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

From: Si-Wei Liu <hidden>
Date: 2021-12-15 20:52:39


On 12/14/2021 6:06 PM, Jason Wang wrote:
On Wed, Dec 15, 2021 at 9:05 AM Si-Wei Liu [off-list ref] wrote:
quoted

On 12/13/2021 9:06 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Dec 13, 2021 at 05:59:45PM -0800, Si-Wei Liu wrote:
quoted
On 12/12/2021 1:26 AM, Michael S. Tsirkin wrote:
quoted
On Fri, Dec 10, 2021 at 05:44:15PM -0800, Si-Wei Liu wrote:
quoted
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?
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.
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
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.
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
quoted
quoted
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
quoted
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
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
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.
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
Thanks


quoted
Meanwhile, I'll check internally to see if a legacy only model would
work. Thanks.

Thanks,
-Siwei

quoted
quoted
quoted
quoted
On 3/2/2021 2:53 AM, Jason Wang wrote:
quoted
On 2021/3/2 5:47 下午, Michael S. Tsirkin wrote:
quoted
On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
quoted
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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
     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

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

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-12-15 21:33:36

On Wed, Dec 15, 2021 at 12:52:20PM -0800, Si-Wei Liu wrote:

On 12/14/2021 6:06 PM, Jason Wang wrote:
quoted
On Wed, Dec 15, 2021 at 9:05 AM Si-Wei Liu [off-list ref] wrote:
quoted

On 12/13/2021 9:06 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Dec 13, 2021 at 05:59:45PM -0800, Si-Wei Liu wrote:
quoted
On 12/12/2021 1:26 AM, Michael S. Tsirkin wrote:
quoted
On Fri, Dec 10, 2021 at 05:44:15PM -0800, Si-Wei Liu wrote:
quoted
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?
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.
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
quoted
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
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.
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
quoted
quoted
quoted
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
quoted
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
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
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.
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

My suggestion is post the kernel patches, and we can evaluate
how much work they are.
quoted
Thanks


quoted
Meanwhile, I'll check internally to see if a legacy only model would
work. Thanks.

Thanks,
-Siwei

quoted
quoted
quoted
quoted
On 3/2/2021 2:53 AM, Jason Wang wrote:
quoted
On 2021/3/2 5:47 下午, Michael S. Tsirkin wrote:
quoted
On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
quoted
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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
     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

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

From: Si-Wei Liu <hidden>
Date: 2021-12-16 02:02:15


On 12/15/2021 1:33 PM, Michael S. Tsirkin wrote:
On Wed, Dec 15, 2021 at 12:52:20PM -0800, Si-Wei Liu wrote:
quoted
On 12/14/2021 6:06 PM, Jason Wang wrote:
quoted
On Wed, Dec 15, 2021 at 9:05 AM Si-Wei Liu [off-list ref] wrote:
quoted
On 12/13/2021 9:06 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Dec 13, 2021 at 05:59:45PM -0800, Si-Wei Liu wrote:
quoted
On 12/12/2021 1:26 AM, Michael S. Tsirkin wrote:
quoted
On Fri, Dec 10, 2021 at 05:44:15PM -0800, Si-Wei Liu wrote:
quoted
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?
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.
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
quoted
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
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.
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?
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
quoted
quoted
quoted
quoted
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
quoted
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
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
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.
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
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
quoted
Thanks


quoted
Meanwhile, I'll check internally to see if a legacy only model would
work. Thanks.

Thanks,
-Siwei

quoted
quoted
quoted
quoted
On 3/2/2021 2:53 AM, Jason Wang wrote:
quoted
On 2021/3/2 5:47 下午, Michael S. Tsirkin wrote:
quoted
On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
quoted
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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
      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

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

From: Jason Wang <hidden>
Date: 2021-12-16 02:53:36

On Thu, Dec 16, 2021 at 10:02 AM Si-Wei Liu [off-list ref] wrote:


On 12/15/2021 1:33 PM, Michael S. Tsirkin wrote:
quoted
On Wed, Dec 15, 2021 at 12:52:20PM -0800, Si-Wei Liu wrote:
quoted
On 12/14/2021 6:06 PM, Jason Wang wrote:
quoted
On Wed, Dec 15, 2021 at 9:05 AM Si-Wei Liu [off-list ref] wrote:
quoted
On 12/13/2021 9:06 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Dec 13, 2021 at 05:59:45PM -0800, Si-Wei Liu wrote:
quoted
On 12/12/2021 1:26 AM, Michael S. Tsirkin wrote:
quoted
On Fri, Dec 10, 2021 at 05:44:15PM -0800, Si-Wei Liu wrote:
quoted
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?
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.
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
quoted
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
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.
meaning guest not acknowledging
quoted
quoted
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.
Noted we don't yet have a set_device_features()
quoted
quoted
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
For software virtio, all support for the legacy part in
quoted
quoted
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
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
quoted
quoted
quoted
quoted
quoted
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
quoted
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
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
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.
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
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
quoted
quoted
Thanks


quoted
Meanwhile, I'll check internally to see if a legacy only model would
work. Thanks.

Thanks,
-Siwei

quoted
quoted
quoted
quoted
On 3/2/2021 2:53 AM, Jason Wang wrote:
quoted
On 2021/3/2 5:47 下午, Michael S. Tsirkin wrote:
quoted
On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
quoted
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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
      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

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

From: Jason Wang <hidden>
Date: 2021-12-16 03:43:54

On Thu, Dec 16, 2021 at 4:52 AM Si-Wei Liu [off-list ref] wrote:


On 12/14/2021 6:06 PM, Jason Wang wrote:
quoted
On Wed, Dec 15, 2021 at 9:05 AM Si-Wei Liu [off-list ref] wrote:
quoted

On 12/13/2021 9:06 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Dec 13, 2021 at 05:59:45PM -0800, Si-Wei Liu wrote:
quoted
On 12/12/2021 1:26 AM, Michael S. Tsirkin wrote:
quoted
On Fri, Dec 10, 2021 at 05:44:15PM -0800, Si-Wei Liu wrote:
quoted
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?
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.
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.
The control VQ is implemented in software in the
kernel, which can be easily accommodated/fixed when needed.
quoted
quoted
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
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
quoted
quoted
quoted
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
quoted
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
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
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.
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).
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
Thanks,
-Siwei
quoted
Thanks


quoted
Meanwhile, I'll check internally to see if a legacy only model would
work. Thanks.

Thanks,
-Siwei

quoted
quoted
quoted
quoted
On 3/2/2021 2:53 AM, Jason Wang wrote:
quoted
On 2021/3/2 5:47 下午, Michael S. Tsirkin wrote:
quoted
On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
quoted
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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
     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

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

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: 2021-12-16 06:35:17

On Wed, Dec 15, 2021 at 06:01:55PM -0800, Si-Wei Liu wrote:

On 12/15/2021 1:33 PM, Michael S. Tsirkin wrote:
quoted
On Wed, Dec 15, 2021 at 12:52:20PM -0800, Si-Wei Liu wrote:
quoted
On 12/14/2021 6:06 PM, Jason Wang wrote:
quoted
On Wed, Dec 15, 2021 at 9:05 AM Si-Wei Liu [off-list ref] wrote:
quoted
On 12/13/2021 9:06 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Dec 13, 2021 at 05:59:45PM -0800, Si-Wei Liu wrote:
quoted
On 12/12/2021 1:26 AM, Michael S. Tsirkin wrote:
quoted
On Fri, Dec 10, 2021 at 05:44:15PM -0800, Si-Wei Liu wrote:
quoted
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?
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.
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
quoted
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
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.
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
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
quoted
quoted
quoted
quoted
quoted
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
quoted
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
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
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.
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
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
quoted
quoted
Thanks


quoted
Meanwhile, I'll check internally to see if a legacy only model would
work. Thanks.

Thanks,
-Siwei

quoted
quoted
quoted
quoted
On 3/2/2021 2:53 AM, Jason Wang wrote:
quoted
On 2021/3/2 5:47 下午, Michael S. Tsirkin wrote:
quoted
On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
quoted
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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
      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

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

From: Si-Wei Liu <hidden>
Date: 2021-12-16 22:32:51


On 12/15/2021 6:53 PM, Jason Wang wrote:
On Thu, Dec 16, 2021 at 10:02 AM Si-Wei Liu [off-list ref] wrote:
quoted

On 12/15/2021 1:33 PM, Michael S. Tsirkin wrote:
quoted
On Wed, Dec 15, 2021 at 12:52:20PM -0800, Si-Wei Liu wrote:
quoted
On 12/14/2021 6:06 PM, Jason Wang wrote:
quoted
On Wed, Dec 15, 2021 at 9:05 AM Si-Wei Liu [off-list ref] wrote:
quoted
On 12/13/2021 9:06 PM, Michael S. Tsirkin wrote:
quoted
On Mon, Dec 13, 2021 at 05:59:45PM -0800, Si-Wei Liu wrote:
quoted
On 12/12/2021 1:26 AM, Michael S. Tsirkin wrote:
quoted
On Fri, Dec 10, 2021 at 05:44:15PM -0800, Si-Wei Liu wrote:
quoted
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?
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.
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
quoted
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
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
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.
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
meaning guest not acknowledging
quoted
quoted
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
Noted we don't yet have a set_device_features()
quoted
quoted
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).
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
  Qemu then knows for
sure it talks to a transitional device or modern only device.

Thanks
quoted
For software virtio, all support for the legacy part in
quoted
quoted
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
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
quoted
quoted
quoted
quoted
quoted
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
quoted
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
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
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.
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
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
quoted
quoted
Thanks


quoted
Meanwhile, I'll check internally to see if a legacy only model would
work. Thanks.

Thanks,
-Siwei

quoted
quoted
quoted
quoted
On 3/2/2021 2:53 AM, Jason Wang wrote:
quoted
On 2021/3/2 5:47 下午, Michael S. Tsirkin wrote:
quoted
On Mon, Mar 01, 2021 at 11:56:50AM +0800, Jason Wang wrote:
quoted
On 2021/3/1 5:34 上午, Michael S. Tsirkin wrote:
quoted
On Wed, Feb 24, 2021 at 10:24:41AM -0800, Si-Wei Liu wrote:
quoted
quoted
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
       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

Next 5 of 5 remaining
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help