From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 84295A0093; Mon, 7 Mar 2022 19:11:44 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1F9C440688; Mon, 7 Mar 2022 19:11:44 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 660BE4014E for ; Mon, 7 Mar 2022 19:11:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646676701; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0DkCmzfPBy5SUuBqNcfAlSJz5fboSUghg+2NPa0f7j0=; b=RJIkQYJIA926WgV+EC9a3G/zhZGRhmt040JzYti6qpiP8DjDzGyPQEIl7nCkDZRMPAt0Jt KQ/9DFpUTDcpEaaljbxaygvBNe29aik5e8C+KyUBLTih6dMabf5SH+S9dCoS5+b5EJzFY0 D4JT4Arb52f39MPuhHrq6f0+ODLQGKw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-576-vFd8CpkyPR6LiN1mIklTUA-1; Mon, 07 Mar 2022 13:11:38 -0500 X-MC-Unique: vFd8CpkyPR6LiN1mIklTUA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 516501091DA0; Mon, 7 Mar 2022 18:11:37 +0000 (UTC) Received: from dmarchan.remote.csb (unknown [10.40.194.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10D29825F7; Mon, 7 Mar 2022 18:11:29 +0000 (UTC) From: David Marchand To: dev@dpdk.org, roy.fan.zhang@intel.com, Maxime Coquelin , Chenbo Xia , Christophe Fontaine Subject: [PATCH] vhost: fix external message handlers Date: Mon, 7 Mar 2022 19:11:01 +0100 Message-Id: <20220307181101.10394-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david.marchand@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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") Signed-off-by: David Marchand --- This patch is untested, but sending quickly to get feedback from the reporter and comments from author and maintainers. --- lib/vhost/vhost_user.c | 8 ++++---- lib/vhost/vhost_user.h | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c index 723c6890c3..589b950458 100644 --- a/lib/vhost/vhost_user.c +++ b/lib/vhost/vhost_user.c @@ -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); diff --git a/lib/vhost/vhost_user.h b/lib/vhost/vhost_user.h index be53669f3b..555f89c97a 100644 --- a/lib/vhost/vhost_user.h +++ b/lib/vhost/vhost_user.h @@ -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. + */ +__rte_packed struct 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) -- 2.23.0