Skip to contentSkip to conversation

vhost-vdpa: don't initialize backend_features

PATCH In review Jason Wang 2 participants 8 messages Jun 2, 2021 – Jun 8, 2021 Networking

lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH 1/2 vhost-vdpa: don't initialize backend_features

We used to initialize backend_features during vhost_vdpa_init() regardless whether or not it was supported by vhost. This will lead the unsupported features like VIRTIO_F_IN_ORDER to be included and set to the vhost-vdpa during vhost_dev_start. Because the VIRTIO_F_IN_ORDER is not supported by vhost-vdpa so it won't be advertised to guest which will break the datapath.

Fix this by not initializing the backend_features, so the acked_features could be built only from guest features via vhost_net_ack_features().

Fixes 108a64818e69b ("vhost-vdpa: introduce vhost-vdpa backend")
Cc Gautam Dawar <[email protected]>
---
 hw/virtio/vhost-vdpa.c | 3 ---
 1 file changed, 3 deletions(-)
hw/virtio/vhost-vdpa.c +0 -3
index 01d2101d09..5fe43a4eb5 100644
@@ -275,15 +275,12 @@ static void vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status)
 static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque)
 {
     struct vhost_vdpa *v;
-    uint64_t features;
     assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA);
     trace_vhost_vdpa_init(dev, opaque);
 
     v = opaque;
     v->dev = dev;
     dev->opaque =  opaque ;
-    vhost_vdpa_call(dev, VHOST_GET_FEATURES, &features);
-    dev->backend_features = features;
     v->listener = vhost_vdpa_memory_listener;
     v->msg_type = VHOST_IOTLB_MSG_V2;
 
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 2/2 vhost-vdpa: remove the unused vhost_vdpa_get_acked_features()

No user for this helper, let's remove it.

---
 include/net/vhost-vdpa.h | 1 -
 net/vhost-vdpa.c         | 9 ---------
 2 files changed, 10 deletions(-)
include/net/vhost-vdpa.h +0 -1
index 45e34b7cfc..b81f9a6f2a 100644
@@ -15,7 +15,6 @@
 #define TYPE_VHOST_VDPA "vhost-vdpa"
 
 struct vhost_net *vhost_vdpa_get_vhost_net(NetClientState *nc);
-uint64_t vhost_vdpa_get_acked_features(NetClientState *nc);
 
 extern const int vdpa_feature_bits[];
 
net/vhost-vdpa.c +0 -9
index fe659ec9e2..8dc86332a6 100644
@@ -66,15 +66,6 @@ VHostNetState *vhost_vdpa_get_vhost_net(NetClientState *nc)
     return s->vhost_net;
 }
 
-uint64_t vhost_vdpa_get_acked_features(NetClientState *nc)
-{
-    VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc);
-    assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA);
-    s->acked_features = vhost_net_get_acked_features(s->vhost_net);
-
-    return s->acked_features;
-}
-
 static int vhost_vdpa_net_check_device_id(struct vhost_net *net)
 {
     uint32_t device_id;
Signature · 1 line
2.25.1
#2 lore raw

RE: [PATCH 2/2] vhost-vdpa: remove the unused vhost_vdpa_get_acked_features()

No user for this helper, let's remove it.

[GD>>] These patches seem unrelated to me. Do you think they should be part of one patch series?

---
 include/net/vhost-vdpa.h | 1 -
 net/vhost-vdpa.c         | 9 ---------
 2 files changed, 10 deletions(-)
include/net/vhost-vdpa.h +0 -0
@@ -15,7 +15,6 @@
 #define TYPE_VHOST_VDPA "vhost-vdpa"
 
 struct vhost_net *vhost_vdpa_get_vhost_net(NetClientState *nc); -uint64_t vhost_vdpa_get_acked_features(NetClientState *nc);
 
 extern const int vdpa_feature_bits[];
 
net/vhost-vdpa.c +0 -9
@@ -66,15 +66,6 @@ VHostNetState *vhost_vdpa_get_vhost_net(NetClientState *nc)
     return s->vhost_net;
 }
 
-uint64_t vhost_vdpa_get_acked_features(NetClientState *nc) -{
-    VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc);
-    assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA);
-    s->acked_features = vhost_net_get_acked_features(s->vhost_net);
-
-    return s->acked_features;
-}
-
 static int vhost_vdpa_net_check_device_id(struct vhost_net *net)  {
     uint32_t device_id;
--

2.25.1

author
#3 lore raw

Re: [PATCH 2/2] vhost-vdpa: remove the unused vhost_vdpa_get_acked_features()

Quoted 3 lines · Gautam Dawar

No user for this helper, let's remove it.

[GD>>] These patches seem unrelated to me. Do you think they should be part of one patch series?

It doesn't harm.

I've queued this patch.

Thanks

Quoted 37 lines
---
  include/net/vhost-vdpa.h | 1 -
  net/vhost-vdpa.c         | 9 ---------
  2 files changed, 10 deletions(-)
include/net/vhost-vdpa.h +0 -0
@@ -15,7 +15,6 @@
  #define TYPE_VHOST_VDPA "vhost-vdpa"
 
  struct vhost_net *vhost_vdpa_get_vhost_net(NetClientState *nc); -uint64_t vhost_vdpa_get_acked_features(NetClientState *nc);
 
  extern const int vdpa_feature_bits[];
 
net/vhost-vdpa.c +0 -9
@@ -66,15 +66,6 @@ VHostNetState *vhost_vdpa_get_vhost_net(NetClientState *nc)
      return s->vhost_net;
  }
 
-uint64_t vhost_vdpa_get_acked_features(NetClientState *nc) -{
-    VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc);
-    assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA);
-    s->acked_features = vhost_net_get_acked_features(s->vhost_net);
-
-    return s->acked_features;
-}
-
  static int vhost_vdpa_net_check_device_id(struct vhost_net *net)  {
      uint32_t device_id;
--

2.25.1

#4 lore raw
In reply to Jason Wang

Hi Jason,

Pls see my comments inline marked by GD>>

Regards,
Gautam

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Wednesday, June 2, 2021 9:01 AM
To: [email protected]; [email protected]
Cc: Gautam Dawar <[email protected]>; [email protected]; Jason Wang <[email protected]>; [email protected]
Subject: [PATCH 1/2] vhost-vdpa: don't initialize backend_features

We used to initialize backend_features during vhost_vdpa_init() regardless whether or not it was supported by vhost. This will lead the unsupported features like VIRTIO_F_IN_ORDER to be included and set to the vhost-vdpa during vhost_dev_start. Because the VIRTIO_F_IN_ORDER is not supported by vhost-vdpa so it won't be advertised to guest which will break the datapath.

Fix this by not initializing the backend_features, so the acked_features could be built only from guest features via vhost_net_ack_features().

Fixes 108a64818e69b ("vhost-vdpa: introduce vhost-vdpa backend")
Cc Gautam Dawar <[email protected]>
---
 hw/virtio/vhost-vdpa.c | 3 ---
 1 file changed, 3 deletions(-)
hw/virtio/vhost-vdpa.c +0 -3
@@ -275,15 +275,12 @@ static void vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status)  static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque)  {
     struct vhost_vdpa *v;
-    uint64_t features;
     assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA);
     trace_vhost_vdpa_init(dev, opaque);
 
     v = opaque;
     v->dev = dev;
     dev->opaque =  opaque ;
-    vhost_vdpa_call(dev, VHOST_GET_FEATURES, &features);
-    dev->backend_features = features;

[GD>>] Should this be initialized with 0 here? I am not sure if memory allocated for struct vhost_dev is initialized with 0.

     v->listener = vhost_vdpa_memory_listener;
     v->msg_type = VHOST_IOTLB_MSG_V2;

--
2.25.1

author
#5 lore raw

Hi Gautam:

Quoted 40 lines · Gautam Dawar

Hi Jason,

Pls see my comments inline marked by GD>>

Regards,
Gautam

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Wednesday, June 2, 2021 9:01 AM
To: [email protected]; [email protected]
Cc: Gautam Dawar <[email protected]>; [email protected]; Jason Wang <[email protected]>; [email protected]
Subject: [PATCH 1/2] vhost-vdpa: don't initialize backend_features

We used to initialize backend_features during vhost_vdpa_init() regardless whether or not it was supported by vhost. This will lead the unsupported features like VIRTIO_F_IN_ORDER to be included and set to the vhost-vdpa during vhost_dev_start. Because the VIRTIO_F_IN_ORDER is not supported by vhost-vdpa so it won't be advertised to guest which will break the datapath.

Fix this by not initializing the backend_features, so the acked_features could be built only from guest features via vhost_net_ack_features().

Fixes 108a64818e69b ("vhost-vdpa: introduce vhost-vdpa backend")
Cc Gautam Dawar <[email protected]>
---
  hw/virtio/vhost-vdpa.c | 3 ---
  1 file changed, 3 deletions(-)
hw/virtio/vhost-vdpa.c +0 -3
@@ -275,15 +275,12 @@ static void vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status)  static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque)  {
      struct vhost_vdpa *v;
-    uint64_t features;
      assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA);
      trace_vhost_vdpa_init(dev, opaque);
 
      v = opaque;
      v->dev = dev;
      dev->opaque =  opaque ;
-    vhost_vdpa_call(dev, VHOST_GET_FEATURES, &features);
-    dev->backend_features = features;
Quoted 1 line

[GD>>] Should this be initialized with 0 here? I am not sure if memory allocated for struct vhost_dev is initialized with 0.

See vhost_net_init:

    struct vhost_net *net = g_new0(struct vhost_net, 1);

vhost_dev is embedded in the vhost_net structure. So I think it should be zero.

Thanks

Quoted 6 lines
      v->listener = vhost_vdpa_memory_listener;
      v->msg_type = VHOST_IOTLB_MSG_V2;

--
2.25.1

Acked-by
#6 lore raw

Hi Jason,

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Wednesday, June 2, 2021 2:18 PM
To: Gautam Dawar <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [PATCH 1/2] vhost-vdpa: don't initialize backend_features

Hi Gautam:

Quoted 42 lines · Gautam Dawar

Hi Jason,

Pls see my comments inline marked by GD>>

Regards,
Gautam

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Wednesday, June 2, 2021 9:01 AM
To: [email protected]; [email protected]
Cc: Gautam Dawar <[email protected]>; [email protected]; Jason Wang <[email protected]>; [email protected]
Subject: [PATCH 1/2] vhost-vdpa: don't initialize backend_features

We used to initialize backend_features during vhost_vdpa_init() regardless whether or not it was supported by vhost. This will lead the unsupported features like VIRTIO_F_IN_ORDER to be included and set to the vhost-vdpa during vhost_dev_start. Because the VIRTIO_F_IN_ORDER is not supported by vhost-vdpa so it won't be advertised to guest which will break the datapath.

Fix this by not initializing the backend_features, so the acked_features could be built only from guest features via vhost_net_ack_features().

Fixes 108a64818e69b ("vhost-vdpa: introduce vhost-vdpa backend")
Cc Gautam Dawar <[email protected]>
---
  hw/virtio/vhost-vdpa.c | 3 ---
  1 file changed, 3 deletions(-)
hw/virtio/vhost-vdpa.c index renamed from hw/virtio/vhost-vdpa.c +0 -0

01d2101d09..5fe43a4eb5 100644

hw/virtio/vhost-vdpa.c +0 -3
@@ -275,15 +275,12 @@ static void vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status)  static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque)  {
      struct vhost_vdpa *v;
-    uint64_t features;
      assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA);
      trace_vhost_vdpa_init(dev, opaque);
 
      v = opaque;
      v->dev = dev;
      dev->opaque =  opaque ;
-    vhost_vdpa_call(dev, VHOST_GET_FEATURES, &features);
-    dev->backend_features = features;
Quoted 1 line

[GD>>] Should this be initialized with 0 here? I am not sure if memory allocated for struct vhost_dev is initialized with 0.

See vhost_net_init:

    struct vhost_net *net = g_new0(struct vhost_net, 1);

vhost_dev is embedded in the vhost_net structure. So I think it should be zero.

[GD>>] That's correct. The embedded vhost_dev structure is indeed getting cleared to 0 in vhost_net_init(). Thanks

Quoted 6 lines
      v->listener = vhost_vdpa_memory_listener;
      v->msg_type = VHOST_IOTLB_MSG_V2;

--
2.25.1

author
#7 lore raw
Quoted 58 lines · Gautam Dawar

Hi Jason,

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Wednesday, June 2, 2021 2:18 PM
To: Gautam Dawar <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [PATCH 1/2] vhost-vdpa: don't initialize backend_features

Hi Gautam:

Quoted 42 lines · Gautam Dawar

Hi Jason,

Pls see my comments inline marked by GD>>

Regards,
Gautam

-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Wednesday, June 2, 2021 9:01 AM
To: [email protected]; [email protected]
Cc: Gautam Dawar <[email protected]>; [email protected]; Jason Wang <[email protected]>; [email protected]
Subject: [PATCH 1/2] vhost-vdpa: don't initialize backend_features

We used to initialize backend_features during vhost_vdpa_init() regardless whether or not it was supported by vhost. This will lead the unsupported features like VIRTIO_F_IN_ORDER to be included and set to the vhost-vdpa during vhost_dev_start. Because the VIRTIO_F_IN_ORDER is not supported by vhost-vdpa so it won't be advertised to guest which will break the datapath.

Fix this by not initializing the backend_features, so the acked_features could be built only from guest features via vhost_net_ack_features().

Fixes 108a64818e69b ("vhost-vdpa: introduce vhost-vdpa backend")
Cc Gautam Dawar <[email protected]>
---
   hw/virtio/vhost-vdpa.c | 3 ---
   1 file changed, 3 deletions(-)
hw/virtio/vhost-vdpa.c index renamed from hw/virtio/vhost-vdpa.c +0 -0

01d2101d09..5fe43a4eb5 100644

hw/virtio/vhost-vdpa.c +0 -3
@@ -275,15 +275,12 @@ static void vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status)  static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque)  {
       struct vhost_vdpa *v;
-    uint64_t features;
       assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA);
       trace_vhost_vdpa_init(dev, opaque);
 
       v = opaque;
       v->dev = dev;
       dev->opaque =  opaque ;
-    vhost_vdpa_call(dev, VHOST_GET_FEATURES, &features);
-    dev->backend_features = features;
Quoted 1 line

[GD>>] Should this be initialized with 0 here? I am not sure if memory allocated for struct vhost_dev is initialized with 0.

See vhost_net_init:

Quoted 6 lines
      struct vhost_net *net = g_new0(struct vhost_net, 1);

vhost_dev is embedded in the vhost_net structure. So I think it should be zero.

[GD>>] That's correct. The embedded vhost_dev structure is indeed getting cleared to 0 in vhost_net_init(). Thanks

Ok, I've queued this patch.

Thanks

Quoted 12 lines
Quoted 8 lines

       v->listener = vhost_vdpa_memory_listener;
       v->msg_type = VHOST_IOTLB_MSG_V2;

--
2.25.1