@@ -15,6 +15,7 @@
#include "qemu/osdep.h"
#include "qemu/iov.h"
+#include "qemu/error-report.h"
#include "hw/virtio/virtio-access.h"
#include "hw/virtio/vhost-pci-net.h"
@@ -139,6 +140,18 @@ static uint64_t vpnet_get_features(VirtIODevice *vdev, uint64_t features,
static void vpnet_set_features(VirtIODevice *vdev, uint64_t features)
{
+ static bool need_send;
+ int ret;
+
+ if (need_send) {
+ need_send = 0;
+ ret = vp_slave_send_feature_bits(features);
+ if (ret < 0) {
+ error_report("failed to send feature bits to the master");
+ }
+ } else {
+ need_send = 1;
+ }
}
static void vpnet_get_config(VirtIODevice *vdev, uint8_t *config)
@@ -88,6 +88,27 @@ static void vp_slave_set_features(VhostUserMsg *msg)
& ~(1 << VHOST_USER_F_PROTOCOL_FEATURES);
}
+static int vp_slave_send_u64(int request, uint64_t u64)
+{
+ VhostUserMsg msg = {
+ .request = request,
+ .flags = VHOST_USER_VERSION,
+ .payload.u64 = u64,
+ .size = sizeof(msg.payload.u64),
+ };
+
+ if (vp_slave_write(&vp_slave->chr_be, &msg) < 0) {
+ return -1;
+ }
+
+ return 0;
+}
+
+int vp_slave_send_feature_bits(uint64_t features)
+{
+ return vp_slave_send_u64(VHOST_USER_SET_FEATURES, features);
+}
+
static DeviceState *virtio_to_pci_dev(VirtIODevice *vdev, uint16_t virtio_id)
{
DeviceState *qdev;
@@ -40,4 +40,6 @@ extern int vhost_pci_slave_init(QemuOpts *opts);
extern int vhost_pci_slave_cleanup(void);
+extern int vp_slave_send_feature_bits(uint64_t features);
+
#endif
The slave actively sends the negotiated feature bits to the master. "need_send" is used to detect if the 64-bit feature bits are ready to be sent. Signed-off-by: Wei Wang <wei.w.wang@intel.com> --- hw/net/vhost-pci-net.c | 13 +++++++++++++ hw/virtio/vhost-pci-slave.c | 21 +++++++++++++++++++++ include/hw/virtio/vhost-pci-slave.h | 2 ++ 3 files changed, 36 insertions(+)