From patchwork Thu Jul 2 08:32:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 72803 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E3707A0524; Thu, 2 Jul 2020 10:34:00 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CB5631D727; Thu, 2 Jul 2020 10:33:18 +0200 (CEST) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id D0DE21D727 for ; Thu, 2 Jul 2020 10:33:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593678796; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HKe4YbY95C6CjDp22RPtM+c8/GhVdt/UFQ4k9s8V0Dk=; b=X4jBnq6OO9pG9EfcMjFHUjzzvERQ8cWNtSfZg2zfnsAFqqQazW6Ngfq7xzYLdnJBJNJ9JC +5lWnjPWZppVFcksK7BEw66kWYhuQlsUCE3/U2tTxyGOBia5r2pi69byn8rSlopDQJqVVA XQXid5Ae/nnlFehvqP+Yx26b8gdkOkw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-295-ylOm4nNnM6-uED_cNTi9yw-1; Thu, 02 Jul 2020 04:33:15 -0400 X-MC-Unique: ylOm4nNnM6-uED_cNTi9yw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9CF7F8014D7; Thu, 2 Jul 2020 08:33:13 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (ovpn-112-91.ams2.redhat.com [10.36.112.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DB8910027A6; Thu, 2 Jul 2020 08:33:08 +0000 (UTC) From: Adrian Moreno To: dev@dpdk.org, xiaolong.ye@intel.com, shahafs@mellanox.com, matan@mellanox.com, maxime.coquelin@redhat.com, xiao.w.wang@intel.com, viacheslavo@mellanox.com Cc: jasowang@redhat.com, lulu@redhat.com, Adrian Moreno Date: Thu, 2 Jul 2020 10:32:35 +0200 Message-Id: <20200702083237.1215652-7-amorenoz@redhat.com> In-Reply-To: <20200702083237.1215652-1-amorenoz@redhat.com> References: <20200702083237.1215652-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v2 6/8] vhost: add support for virtio get status message X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch adds support to the new Virtio device get status Vhost-user message. The driver can send this new message to read the device status. One of the uses of this message is to ensure the feature negotiation has succeded. According to the virtio spec, after completing the feature negotiation, the driver sets the FEATURE_OK status bit and re-reads it to ensure the device has accepted the features. This patch also clears the FEATURE_OK status bit if the feature negotiation has failed to let the driver know about his failure. Signed-off-by: Adrian Moreno --- lib/librte_vhost/vhost.h | 2 ++ lib/librte_vhost/vhost_user.c | 32 ++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost_user.h | 1 + 3 files changed, 35 insertions(+) diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index 25d31c71b..e743821cc 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -32,6 +32,8 @@ #define VIRTIO_DEV_BUILTIN_VIRTIO_NET 4 /* Used to indicate that the device has its own data path and configured */ #define VIRTIO_DEV_VDPA_CONFIGURED 8 +/* Used to indicate that the feature negotiation failed */ +#define VIRTIO_DEV_FEATURES_FAILED 16 /* Backend value set by guest. */ #define VIRTIO_DEV_STOPPED -1 diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 8d3d13913..00da7bf18 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -88,6 +88,7 @@ static const char *vhost_message_str[VHOST_USER_MAX] = { [VHOST_USER_GET_INFLIGHT_FD] = "VHOST_USER_GET_INFLIGHT_FD", [VHOST_USER_SET_INFLIGHT_FD] = "VHOST_USER_SET_INFLIGHT_FD", [VHOST_USER_SET_STATUS] = "VHOST_USER_SET_STATUS", + [VHOST_USER_GET_STATUS] = "VHOST_USER_GET_STATUS", }; static int send_vhost_reply(int sockfd, struct VhostUserMsg *msg); @@ -339,6 +340,9 @@ vhost_user_set_features(struct virtio_net **pdev, struct VhostUserMsg *msg, VHOST_LOG_CONFIG(ERR, "(%d) received invalid negotiated features.\n", dev->vid); + dev->flags |= VIRTIO_DEV_FEATURES_FAILED; + dev->status &= ~VIRTIO_DEVICE_STATUS_FEATURES_OK; + return RTE_VHOST_MSG_RESULT_ERR; } @@ -402,6 +406,7 @@ vhost_user_set_features(struct virtio_net **pdev, struct VhostUserMsg *msg, if (vdpa_dev) vdpa_dev->ops->set_features(dev->vid); + dev->flags &= ~VIRTIO_DEV_FEATURES_FAILED; return RTE_VHOST_MSG_RESULT_OK; } @@ -2458,6 +2463,22 @@ vhost_user_postcopy_end(struct virtio_net **pdev, struct VhostUserMsg *msg, return RTE_VHOST_MSG_RESULT_REPLY; } +static int +vhost_user_get_status(struct virtio_net **pdev, struct VhostUserMsg *msg, + int main_fd __rte_unused) +{ + struct virtio_net *dev = *pdev; + + if (validate_msg_fds(msg, 0) != 0) + return RTE_VHOST_MSG_RESULT_ERR; + + msg->payload.u64 = dev->status; + msg->size = sizeof(msg->payload.u64); + msg->fd_num = 0; + + return RTE_VHOST_MSG_RESULT_OK; +} + static int vhost_user_set_status(struct virtio_net **pdev, struct VhostUserMsg *msg, int main_fd __rte_unused) @@ -2476,6 +2497,16 @@ vhost_user_set_status(struct virtio_net **pdev, struct VhostUserMsg *msg, dev->status = msg->payload.u64; + if ((dev->status & VIRTIO_DEVICE_STATUS_FEATURES_OK) && + (dev->flags & VIRTIO_DEV_FEATURES_FAILED)) { + VHOST_LOG_CONFIG(ERR, "FEATURES_OK bit is set but feature negotiation failed\n"); + /* + * Clear the bit to let the driver know about the feature + * negotiation failure + */ + dev->status &= ~VIRTIO_DEVICE_STATUS_FEATURES_OK; + } + VHOST_LOG_CONFIG(INFO, "New device status(0x%08x):\n" "\t-ACKNOWLEDGE: %u\n" "\t-DRIVER: %u\n" @@ -2527,6 +2558,7 @@ static vhost_message_handler_t vhost_message_handlers[VHOST_USER_MAX] = { [VHOST_USER_GET_INFLIGHT_FD] = vhost_user_get_inflight_fd, [VHOST_USER_SET_INFLIGHT_FD] = vhost_user_set_inflight_fd, [VHOST_USER_SET_STATUS] = vhost_user_set_status, + [VHOST_USER_GET_STATUS] = vhost_user_get_status, }; /* return bytes# of read on success or negative val on failure. */ diff --git a/lib/librte_vhost/vhost_user.h b/lib/librte_vhost/vhost_user.h index 82885ab5e..16fe03f88 100644 --- a/lib/librte_vhost/vhost_user.h +++ b/lib/librte_vhost/vhost_user.h @@ -58,6 +58,7 @@ typedef enum VhostUserRequest { VHOST_USER_GET_INFLIGHT_FD = 31, VHOST_USER_SET_INFLIGHT_FD = 32, VHOST_USER_SET_STATUS = 39, + VHOST_USER_GET_STATUS = 40, VHOST_USER_MAX = 41 } VhostUserRequest;