+ int ret;
+ uint32_t i;
+ struct vhost_kernel_data *data = dev->backend_data;
+
+ for (i = 0; i < dev->max_queue_pairs; ++i) {
+ if (data->vhostfds[i] < 0)
+ continue;
+
+ ret = vhost_kernel_ioctl(data->vhostfds[i], VHOST_SET_OWNER, NULL);
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int
+vhost_kernel_get_features(struct virtio_user_dev *dev, uint64_t *features)
+{
+ struct vhost_kernel_data *data = dev->backend_data;
+ unsigned int tap_flags;
+ int ret;
+
+ ret = vhost_kernel_ioctl(data->vhostfds[0], VHOST_GET_FEATURES, features);
+ if (ret < 0) {
+ PMD_DRV_LOG(ERR, "Failed to get features");
+ return -1;
+ }
+
+ ret = tap_get_flags(data->tapfds[0], &tap_flags);
+ if (ret < 0) {
+ PMD_DRV_LOG(ERR, "Failed to get TAP features");
+ return -1;
+ }
+
+ /* with tap as the backend, all these features are supported
+ * but not claimed by vhost-net, so we add them back when
+ * reporting to upper layer.
+ */
+ if (tap_flags & IFF_VNET_HDR) {
+ *features |= VHOST_KERNEL_GUEST_OFFLOADS_MASK;
+ *features |= VHOST_KERNEL_HOST_OFFLOADS_MASK;
+ }
+
+ /* vhost_kernel will not declare this feature, but it does
+ * support multi-queue.
+ */
+ if (tap_flags & IFF_MULTI_QUEUE)
+ *features |= (1ull << VIRTIO_NET_F_MQ);
+
+ return 0;
+}
+
+static int
+vhost_kernel_set_features(struct virtio_user_dev *dev, uint64_t features)
+{
+ struct vhost_kernel_data *data = dev->backend_data;
+ uint32_t i;
+ int ret;
+
+ /* We don't need memory protection here */
+ features &= ~(1ULL << VIRTIO_F_IOMMU_PLATFORM);
+ /* VHOST kernel does not know about below flags */
+ features &= ~VHOST_KERNEL_GUEST_OFFLOADS_MASK;
+ features &= ~VHOST_KERNEL_HOST_OFFLOADS_MASK;
+ features &= ~(1ULL << VIRTIO_NET_F_MQ);
+
+ for (i = 0; i < dev->max_queue_pairs; ++i) {
+ if (data->vhostfds[i] < 0)
+ continue;
+
+ ret = vhost_kernel_ioctl(data->vhostfds[i], VHOST_SET_FEATURES, &features);
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int
+add_memseg_list(const struct rte_memseg_list *msl, void *arg)
+{
+ struct vhost_memory_kernel *vm = arg;