vhost: fix external message handlers
authorDavid Marchand <david.marchand@redhat.com>
Tue, 8 Mar 2022 09:44:22 +0000 (10:44 +0100)
committerDavid Marchand <david.marchand@redhat.com>
Tue, 8 Mar 2022 14:48:30 +0000 (15:48 +0100)
Following a rework, external message handlers were receiving a pointer
to a vhost_user message (as stated in the API), but lost the ability to
interact with fds attached to the message.
Restore the original layout and put a build check and reminders.

Bugzilla ID: 953
Fixes: 5e0099dc709e ("vhost: remove payload size limitation")

Reported-by: Fan Zhang <roy.fan.zhang@intel.com>
Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Tested-by: Jakub Poczatek <jakub.poczatek@intel.com>
Acked-by: Jakub Poczatek <jakub.poczatek@intel.com>
Reviewed-by: Christophe Fontaine <cfontain@redhat.com>
lib/vhost/vhost_user.c
lib/vhost/vhost_user.h

index 723c689..589b950 100644 (file)
@@ -3023,8 +3023,8 @@ vhost_user_msg_handler(int vid, int fd)
 
        handled = false;
        if (dev->extern_ops.pre_msg_handle) {
-               ret = (*dev->extern_ops.pre_msg_handle)(dev->vid,
-                               (void *)&ctx.msg);
+               RTE_BUILD_BUG_ON(offsetof(struct vhu_msg_context, msg) != 0);
+               ret = (*dev->extern_ops.pre_msg_handle)(dev->vid, &ctx);
                switch (ret) {
                case RTE_VHOST_MSG_RESULT_REPLY:
                        send_vhost_reply(dev, fd, &ctx);
@@ -3069,8 +3069,8 @@ vhost_user_msg_handler(int vid, int fd)
 skip_to_post_handle:
        if (ret != RTE_VHOST_MSG_RESULT_ERR &&
                        dev->extern_ops.post_msg_handle) {
-               ret = (*dev->extern_ops.post_msg_handle)(dev->vid,
-                               (void *)&ctx.msg);
+               RTE_BUILD_BUG_ON(offsetof(struct vhu_msg_context, msg) != 0);
+               ret = (*dev->extern_ops.post_msg_handle)(dev->vid, &ctx);
                switch (ret) {
                case RTE_VHOST_MSG_RESULT_REPLY:
                        send_vhost_reply(dev, fd, &ctx);
index be53669..c946cc2 100644 (file)
@@ -152,10 +152,13 @@ typedef struct VhostUserMsg {
        /* Nothing should be added after the payload */
 } __rte_packed VhostUserMsg;
 
-struct vhu_msg_context {
+/* Note: this structure and VhostUserMsg can't be changed carelessly as
+ * external message handlers rely on them.
+ */
+struct __rte_packed vhu_msg_context {
+       VhostUserMsg msg;
        int fds[VHOST_MEMORY_MAX_NREGIONS];
        int fd_num;
-       VhostUserMsg msg;
 };
 
 #define VHOST_USER_HDR_SIZE offsetof(VhostUserMsg, payload.u64)