From 231f986bd9907845785f4899394fa27f7c8a07e3 Mon Sep 17 00:00:00 2001 From: Liu Long Date: Wed, 11 May 2022 09:55:16 +0800 Subject: [PATCH] ACRN: DM: Expose the vhost kernel ioctrl API The patch expose the vhost kernel ioctrl API and remove the virtio_net operation functions to the virtio_net code module. Tracked-On: #7456 Signed-off-by: Liu Long Reviewed-by: Conghui Acked-by: Wang, Yu1 --- devicemodel/hw/pci/virtio/vhost.c | 45 +------------------------- devicemodel/hw/pci/virtio/virtio_net.c | 35 ++++++++++++++++++-- devicemodel/include/vhost.h | 18 ++++------- 3 files changed, 41 insertions(+), 57 deletions(-) diff --git a/devicemodel/hw/pci/virtio/vhost.c b/devicemodel/hw/pci/virtio/vhost.c index f7c95662d..15b926014 100644 --- a/devicemodel/hw/pci/virtio/vhost.c +++ b/devicemodel/hw/pci/virtio/vhost.c @@ -31,7 +31,7 @@ static int vhost_debug; do { if (vhost_debug) pr_dbg(LOG_TAG fmt, ##args); } while (0) #define WPRINTF(fmt, args...) pr_err(LOG_TAG fmt, ##args) -static inline +inline int vhost_kernel_ioctl(struct vhost_dev *vdev, unsigned long int request, void *arg) @@ -154,13 +154,6 @@ vhost_kernel_reset_device(struct vhost_dev *vdev) return vhost_kernel_ioctl(vdev, VHOST_RESET_OWNER, NULL); } -static int -vhost_kernel_net_set_backend(struct vhost_dev *vdev, - struct vhost_vring_file *file) -{ - return vhost_kernel_ioctl(vdev, VHOST_NET_SET_BACKEND, file); -} - static int vhost_eventfd_test_and_clear(int fd) { @@ -772,39 +765,3 @@ vhost_dev_stop(struct vhost_dev *vdev) vdev->started = false; return rc; } - -/** - * @brief set backend fd of vhost net. - * - * This interface is called to set the backend fd (for example tap fd) - * to vhost. - * - * @param vdev Pointer to struct vhost_dev. - * @param backend_fd fd of backend (for example tap fd). - * - * @return 0 on success and -1 on failure. - */ -int -vhost_net_set_backend(struct vhost_dev *vdev, int backend_fd) -{ - struct vhost_vring_file file; - int rc, i; - - file.fd = backend_fd; - for (i = 0; i < vdev->nvqs; i++) { - file.index = i; - rc = vhost_kernel_net_set_backend(vdev, &file); - if (rc < 0) - goto fail; - } - - return 0; -fail: - file.fd = -1; - while (--i >= 0) { - file.index = i; - vhost_kernel_net_set_backend(vdev, &file); - } - - return -1; -} diff --git a/devicemodel/hw/pci/virtio/virtio_net.c b/devicemodel/hw/pci/virtio/virtio_net.c index 41de92258..563443d2b 100644 --- a/devicemodel/hw/pci/virtio/virtio_net.c +++ b/devicemodel/hw/pci/virtio/virtio_net.c @@ -43,6 +43,7 @@ #include #include #include +#include #include "dm.h" #include "pci_core.h" @@ -76,8 +77,6 @@ #define VIRTIO_NET_F_CTRL_VLAN (1 << 19) /* control channel VLAN filtering */ #define VIRTIO_NET_F_GUEST_ANNOUNCE \ (1 << 21) /* guest can send gratuitous pkts */ -#define VHOST_NET_F_VIRTIO_NET_HDR \ - (1 << 27) /* vhost provides virtio_net_hdr */ #define VIRTIO_NET_S_HOSTCAPS \ (VIRTIO_NET_F_MAC | VIRTIO_NET_F_MRG_RXBUF | VIRTIO_NET_F_STATUS | \ @@ -202,6 +201,38 @@ static struct virtio_ops virtio_net_ops = { virtio_net_set_status, /* called on guest set status */ }; +static int +vhost_kernel_net_set_backend(struct vhost_dev *vdev, + struct vhost_vring_file *file) +{ + return vhost_kernel_ioctl(vdev, VHOST_NET_SET_BACKEND, file); +} + +int +vhost_net_set_backend(struct vhost_dev *vdev, int backend_fd) +{ + struct vhost_vring_file file; + int rc, i; + + file.fd = backend_fd; + for (i = 0; i < vdev->nvqs; i++) { + file.index = i; + rc = vhost_kernel_net_set_backend(vdev, &file); + if (rc < 0) + goto fail; + } + + return 0; +fail: + file.fd = -1; + while (--i >= 0) { + file.index = i; + vhost_kernel_net_set_backend(vdev, &file); + } + + return -1; +} + static struct ether_addr * ether_aton(const char *a, struct ether_addr *e) { diff --git a/devicemodel/include/vhost.h b/devicemodel/include/vhost.h index 1dfaff954..bea28af16 100644 --- a/devicemodel/include/vhost.h +++ b/devicemodel/include/vhost.h @@ -132,19 +132,15 @@ int vhost_dev_start(struct vhost_dev *vdev); int vhost_dev_stop(struct vhost_dev *vdev); /** - * @brief set backend fd of vhost net. + * @brief vhost kernel dev ioctrl function * - * This interface is called to set the backend fd (for example tap fd) - * to vhost. + * This interface is used to operation the vhost dev kernel. * - * @param vdev Pointer to struct vhost_dev. - * @param backend_fd fd of backend (for example tap fd). + * @param vdev Pointer to struct vhost_dev + * @param The request to vhost kernel + * @param The arguments of vhost kernel operation * - * @return 0 on success and -1 on failure. - */ -int vhost_net_set_backend(struct vhost_dev *vdev, int backend_fd); - -/** - * @} + * @return 0 on success and -1 on failure */ +int vhost_kernel_ioctl(struct vhost_dev *vdev, unsigned long int request, void *arg); #endif