From: Li Feng Date: Fri, 20 Dec 2019 08:22:55 +0000 (+0800) Subject: vhost: support config change slave message X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=109c38b2e9aacfb2b5f4f4c28cf4025b444b70f1;p=dpdk.git vhost: support config change slave message This msg is used to notify qemu that should get the config of backend. For example, vhost-user-blk uses this msg to notify guest OS the capacity of backend has changed. The need_reply flag is not mandatory because it will block the sender thread and master process will send get_config message to fetch the configuration, this need an extra thread to process the vhost message. Signed-off-by: Li Feng Reviewed-by: Maxime Coquelin --- diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h index 7b5dc87c2e..c7b619ae0d 100644 --- a/lib/librte_vhost/rte_vhost.h +++ b/lib/librte_vhost/rte_vhost.h @@ -10,6 +10,7 @@ * Interface to vhost-user */ +#include #include #include @@ -977,6 +978,20 @@ __rte_experimental int rte_vhost_get_vdpa_device_id(int vid); +/** + * Notify the guest that should get virtio configuration space from backend. + * + * @param vid + * vhost device ID + * @param need_reply + * wait for the master response the status of this operation + * @return + * 0 on success, < 0 on failure + */ +__rte_experimental +int +rte_vhost_slave_config_change(int vid, bool need_reply); + #ifdef __cplusplus } #endif diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map index c512377fe6..051d08c120 100644 --- a/lib/librte_vhost/rte_vhost_version.map +++ b/lib/librte_vhost/rte_vhost_version.map @@ -65,4 +65,5 @@ EXPERIMENTAL { rte_vhost_clr_inflight_desc_packed; rte_vhost_get_vhost_ring_inflight; rte_vhost_get_vring_base_from_inflight; + rte_vhost_slave_config_change; }; diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 47db316a2f..69b84a8820 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -2840,6 +2840,42 @@ vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm) return 0; } +static int +vhost_user_slave_config_change(struct virtio_net *dev, bool need_reply) +{ + int ret; + struct VhostUserMsg msg = { + .request.slave = VHOST_USER_SLAVE_CONFIG_CHANGE_MSG, + .flags = VHOST_USER_VERSION, + .size = 0, + }; + + if (need_reply) + msg.flags |= VHOST_USER_NEED_REPLY; + + ret = send_vhost_slave_message(dev, &msg); + if (ret < 0) { + VHOST_LOG_CONFIG(ERR, + "Failed to send config change (%d)\n", + ret); + return ret; + } + + return process_slave_message_reply(dev, &msg); +} + +int +rte_vhost_slave_config_change(int vid, bool need_reply) +{ + struct virtio_net *dev; + + dev = get_device(vid); + if (!dev) + return -ENODEV; + + return vhost_user_slave_config_change(dev, need_reply); +} + static int vhost_user_slave_set_vring_host_notifier(struct virtio_net *dev, int index, int fd, uint64_t offset, diff --git a/lib/librte_vhost/vhost_user.h b/lib/librte_vhost/vhost_user.h index 6563f7315b..86c364a935 100644 --- a/lib/librte_vhost/vhost_user.h +++ b/lib/librte_vhost/vhost_user.h @@ -62,6 +62,7 @@ typedef enum VhostUserRequest { typedef enum VhostUserSlaveRequest { VHOST_USER_SLAVE_NONE = 0, VHOST_USER_SLAVE_IOTLB_MSG = 1, + VHOST_USER_SLAVE_CONFIG_CHANGE_MSG = 2, VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG = 3, VHOST_USER_SLAVE_MAX } VhostUserSlaveRequest;