From patchwork Fri Jun 24 08:17:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prerna Saxena X-Patchwork-Id: 9196963 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0FFAF60754 for ; Fri, 24 Jun 2016 08:32:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F21ED27F85 for ; Fri, 24 Jun 2016 08:32:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E6AD52849F; Fri, 24 Jun 2016 08:32:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F1AE427F85 for ; Fri, 24 Jun 2016 08:32:07 +0000 (UTC) Received: from localhost ([::1]:41875 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGMX1-0008R0-3x for patchwork-qemu-devel@patchwork.kernel.org; Fri, 24 Jun 2016 04:32:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35328) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGMIw-00007A-PQ for qemu-devel@nongnu.org; Fri, 24 Jun 2016 04:17:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bGMIr-0002Mp-7f for qemu-devel@nongnu.org; Fri, 24 Jun 2016 04:17:34 -0400 Received: from mail-pa0-x241.google.com ([2607:f8b0:400e:c03::241]:35532) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGMIq-0002Mj-Sn for qemu-devel@nongnu.org; Fri, 24 Jun 2016 04:17:29 -0400 Received: by mail-pa0-x241.google.com with SMTP id hf6so8401263pac.2 for ; Fri, 24 Jun 2016 01:17:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=eUFUQnS92LGuwXKObhsaqItgmwKQMh+V+ZY0peqSTh8=; b=pLJm+dvAV59Nf8TTYLdjODk48ECMioC2xjy2otnj1va9QTbBavnj8TOKGJUuqc9MSY vCJ0oiXhs8OjtzfIiXMUQkZpLN4foxgwkeN4P5WTHgFhFT/WpL/N0WUEQVTmSY/MomXn YUKfgeU8NNc6Y1Zb+Ws8drAjKlFUIqDWE0oxnok+DAx4MVHluQ/PXqh78/VbUj/JxQXC 4rWNGXEh6ETPszG/DWsItQLA4IcQDVtBTDBhXfI6cEAjPAbdD3atNI7c7uneCk6zAa0d udMEnhHSjN7oxgT2Y1jy147jynT5t1z0nT4sl6aozhuxJRbHsyT/5szUhwB22m34VYX5 AU5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=eUFUQnS92LGuwXKObhsaqItgmwKQMh+V+ZY0peqSTh8=; b=Fw9yy8x4XVH4vsd17oWTZiBii9BxRdStC6nEZuOYEpZwwfzNwZz1F6r0Ql3fI8LWMW jPlFZycRLvUMER0hFT0gpVuVayVRaqdGAZDjGc3fyLgM5pd6JPtTaxmVHTUDhydXKtn9 8+pRBHnB/CCZBI/5UoYqTrEB3iQushT7Un9o/ufYpYpNBEvivUFcp9PJ8EuBn6Xw5S1x B+WFlflocB7jPlNJv09fH14p7IDcJdZVFUDnDWaNUWtC/ruqftXetiK0fa3Z4aAgSXmP +xYMjcDL86Tgu9Cpj3H9IeOQrv4SSOTxQ3NVZDyNLNOTYNjqqRh5uaZkFG+HOmnkvqGW ++JQ== X-Gm-Message-State: ALyK8tJOB93jdhgKJum+4eeVqE88VHmSY+nYdXP/x+M3VOHYPSd0MqnIjbnZ9yYhXL04Og== X-Received: by 10.66.15.232 with SMTP id a8mr5324660pad.129.1466756248109; Fri, 24 Jun 2016 01:17:28 -0700 (PDT) Received: from prerna-saxena.dev.eng.nutanix.com. (206-15-90-246.static.twtelecom.net. [206.15.90.246]) by smtp.gmail.com with ESMTPSA id ct7sm5604037pac.13.2016.06.24.01.17.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Jun 2016 01:17:27 -0700 (PDT) From: Prerna Saxena To: qemu-devel@nongnu.org Date: Fri, 24 Jun 2016 01:17:08 -0700 Message-Id: <1466756228-27490-2-git-send-email-saxenap.ltc@gmail.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1466756228-27490-1-git-send-email-saxenap.ltc@gmail.com> References: <1466756228-27490-1-git-send-email-saxenap.ltc@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c03::241 Subject: [Qemu-devel] [PATCH 1/1] vhost-user : Introduce a new feature VHOST_USER_PROTOCOL_F_REPLY_ACK. This feature, if negotiated, forces the remote vhost-user process to send a u64 reply containing a status code for each requested operation. Status codes are '0' for success, and non-zero for error. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Prerna Saxena , anilkumar.boggarapu@nutanix.com, felipe.francoisi@nutanix.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Prerna Saxena Signed-off-by: Prerna Saxena --- docs/specs/vhost-user.txt | 36 +++++++++++ hw/virtio/vhost-user.c | 153 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 186 insertions(+), 3 deletions(-) diff --git a/docs/specs/vhost-user.txt b/docs/specs/vhost-user.txt index 777c49c..e5388b2 100644 --- a/docs/specs/vhost-user.txt +++ b/docs/specs/vhost-user.txt @@ -37,6 +37,7 @@ consists of 3 header fields and a payload: * Flags: 32-bit bit field: - Lower 2 bits are the version (currently 0x01) - Bit 2 is the reply flag - needs to be sent on each reply from the slave + - Bit 3 is the need_response flag - see VHOST_USER_PROTOCOL_F_REPLY_ACK for details. * Size - 32-bit size of the payload @@ -126,6 +127,8 @@ the ones that do: * VHOST_GET_VRING_BASE * VHOST_SET_LOG_BASE (if VHOST_USER_PROTOCOL_F_LOG_SHMFD) +[ Also see the section on REPLY_ACK protocol extension] + There are several messages that the master sends with file descriptors passed in the ancillary data: @@ -254,6 +257,7 @@ Protocol features #define VHOST_USER_PROTOCOL_F_MQ 0 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 #define VHOST_USER_PROTOCOL_F_RARP 2 +#define VHOST_USER_PROTOCOL_F_REPLY_ACK 3 Message types ------------- @@ -464,3 +468,35 @@ Message types is present in VHOST_USER_GET_PROTOCOL_FEATURES. The first 6 bytes of the payload contain the mac address of the guest to allow the vhost user backend to construct and broadcast the fake RARP. + +VHOST_USER_PROTOCOL_F_REPLY_ACK: +-------------------------------- +The original vhost-user specification only demands responses for certain +commands. This differs from the vhost protocol implementation where commands +are sent over an ioctl() call and block until the client has completed. Not +receiving a response for commands like VHOST_SET_MEM_TABLE makes the sender +unable to tell when the client has finished (re)mapping the GPA, or whether it +has failed altogether. + +With this protocol extension negotiated, the sender can set the newly +introduced "need_response" [Bit 3] flag to any command. This indicates that +the client MUST to respond with a Payload VhostUserMsg indicating success or +failure. The payload should be set to zero on success or non-zero on failure. +In other words, response must be in the following format : +------------------------------------ +| request | flags | size | payload | +------------------------------------ + + * Request: 32-bit type of the original request which is being responded to. + * Flags: 32-bit bit field: (VHOST_USER_VERSION | VHOST_USER_REPLY_MASK) + * Size: size of the payload ( see below) + * Payload : a u64 integer, where a non-zero value indicates a failure. + +Note that as per the original vhost-user protocol, the following four messages anyway +require distinct responses from the vhost-user client process : + * VHOST_GET_FEATURES + * VHOST_GET_PROTOCOL_FEATURES + * VHOST_GET_VRING_BASE + * VHOST_SET_LOG_BASE (if VHOST_USER_PROTOCOL_F_LOG_SHMFD) +For these message types, the presence of VHOST_USER_PROTOCOL_F_REPLY_ACK or +need_response bit being set brings no behaviourial change. diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 495e09f..f01ebb4 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -31,6 +31,7 @@ enum VhostUserProtocolFeature { VHOST_USER_PROTOCOL_F_MQ = 0, VHOST_USER_PROTOCOL_F_LOG_SHMFD = 1, VHOST_USER_PROTOCOL_F_RARP = 2, + VHOST_USER_PROTOCOL_F_REPLY_ACK = 3, VHOST_USER_PROTOCOL_F_MAX }; @@ -82,8 +83,9 @@ typedef struct VhostUserLog { typedef struct VhostUserMsg { VhostUserRequest request; -#define VHOST_USER_VERSION_MASK (0x3) -#define VHOST_USER_REPLY_MASK (0x1<<2) +#define VHOST_USER_VERSION_MASK (0x3) +#define VHOST_USER_REPLY_MASK (0x1 << 2) +#define VHOST_USER_NEED_RESPONSE_MASK (0x1 << 3) uint32_t flags; uint32_t size; /* the following payload size */ union { @@ -239,10 +241,17 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev, int fds[VHOST_MEMORY_MAX_NREGIONS]; int i, fd; size_t fd_num = 0; + bool reply_supported = virtio_has_feature(dev->protocol_features, + VHOST_USER_PROTOCOL_F_REPLY_ACK); VhostUserMsg msg = { .request = VHOST_USER_SET_MEM_TABLE, .flags = VHOST_USER_VERSION, }; + VhostUserRequest request = msg.request; + + if (reply_supported) { + msg.flags |= VHOST_USER_NEED_RESPONSE_MASK; + } for (i = 0; i < dev->mem->nregions; ++i) { struct vhost_memory_region *reg = dev->mem->regions + i; @@ -277,6 +286,20 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev, vhost_user_write(dev, &msg, fds, fd_num); + if (reply_supported) { + if (vhost_user_read(dev, &msg) < 0) { + return 0; + } + + if (msg.request != request) { + error_report("Received unexpected msg type." + "Expected %d received %d", + request, msg.request); + return -1; + } + return msg.payload.u64 ? -1 : 0; + } + return 0; } @@ -289,9 +312,29 @@ static int vhost_user_set_vring_addr(struct vhost_dev *dev, .payload.addr = *addr, .size = sizeof(msg.payload.addr), }; + VhostUserRequest request = msg.request; + + bool reply_supported = virtio_has_feature(dev->protocol_features, + VHOST_USER_PROTOCOL_F_REPLY_ACK); + if (reply_supported) { + msg.flags |= VHOST_USER_NEED_RESPONSE_MASK; + } vhost_user_write(dev, &msg, NULL, 0); + if (reply_supported) { + if (vhost_user_read(dev, &msg) < 0) { + return 0; + } + + if (msg.request != request) { + error_report("Received unexpected msg type." + "Expected %d received %d", + request, msg.request); + return -1; + } + return msg.payload.u64 ? -1 : 0; + } return 0; } @@ -313,8 +356,28 @@ static int vhost_set_vring(struct vhost_dev *dev, .size = sizeof(msg.payload.state), }; + bool reply_supported = virtio_has_feature(dev->protocol_features, + VHOST_USER_PROTOCOL_F_REPLY_ACK); + + if (reply_supported) { + msg.flags |= VHOST_USER_NEED_RESPONSE_MASK; + } + vhost_user_write(dev, &msg, NULL, 0); + if (reply_supported) { + if (vhost_user_read(dev, &msg) < 0) { + return 0; + } + + if (msg.request != request) { + error_report("Received unexpected msg type." + "Expected %lu received %lu", + request, msg.request); + return -1; + } + return msg.payload.u64 ? -1 : 0; + } return 0; } @@ -395,6 +458,13 @@ static int vhost_set_vring_file(struct vhost_dev *dev, .size = sizeof(msg.payload.u64), }; + bool reply_Supported = virtio_has_feature(dev->protocol_features, + VHOST_USER_PROTOCOL_F_REPLY_ACK); + + if (reply_supported) { + msg.flags |= VHOST_USER_NEED_RESPONSE_MASK; + } + if (ioeventfd_enabled() && file->fd > 0) { fds[fd_num++] = file->fd; } else { @@ -403,6 +473,20 @@ static int vhost_set_vring_file(struct vhost_dev *dev, vhost_user_write(dev, &msg, fds, fd_num); + if (reply_supported) { + if (vhost_user_read(dev, &msg) < 0) { + return 0; + } + + if (msg.request != request) { + error_report("Received unexpected msg type." + "Expected %d received %d", + request, msg.request); + return -1; + } + return msg.payload.u64 ? -1 : 0; + } + return 0; } @@ -489,8 +573,30 @@ static int vhost_user_set_owner(struct vhost_dev *dev) .flags = VHOST_USER_VERSION, }; + VhostUserRequest request = msg.request; + + bool reply_supported = virtio_has_feature(dev->protocol_features, + VHOST_USER_PROTOCOL_F_REPLY_ACK); + + if (reply_supported) { + msg.flags |= VHOST_USER_NEED_RESPONSE_MASK; + } + vhost_user_write(dev, &msg, NULL, 0); + if (reply_supported) { + if (vhost_user_read(dev, &msg) < 0) { + return 0; + } + + if (msg.request != request) { + error_report("Received unexpected msg type." + "Expected %d received %d", + request, msg.request); + return -1; + } + return msg.payload.u64 ? -1 : 0; + } return 0; } @@ -500,9 +606,30 @@ static int vhost_user_reset_device(struct vhost_dev *dev) .request = VHOST_USER_RESET_OWNER, .flags = VHOST_USER_VERSION, }; + VhostUserRequest request = msg.request; + + bool reply_supported = virtio_has_feature(dev->protocol_features, + VHOST_USER_PROTOCOL_F_REPLY_ACK); + + if (reply_supported) { + msg.flags |= VHOST_USER_NEED_RESPONSE_MASK; + } vhost_user_write(dev, &msg, NULL, 0); + if (reply_suported) { + if (vhost_user_read(dev, &msg) < 0) { + return 0; + } + + if (msg.request != request) { + error_report("Received unexpected msg type." + "Expected %d received %d", + request, msg.request); + return -1; + } + return msg.payload.u64 ? -1 : 0; + } return 0; } @@ -589,9 +716,15 @@ static int vhost_user_migration_done(struct vhost_dev *dev, char* mac_addr) { VhostUserMsg msg = { 0 }; int err; + VhostUserRequest request = msg.request; + bool reply_supported = virtio_has_feature(dev->protocol_features, + VHOST_USER_PROTOCOL_F_REPLY_ACK); assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER); + if (reply_supported) { + msg.flags |= VHOST_USER_NEED_RESPONSE_MASK; + } /* If guest supports GUEST_ANNOUNCE do nothing */ if (virtio_has_feature(dev->acked_features, VIRTIO_NET_F_GUEST_ANNOUNCE)) { return 0; @@ -606,7 +739,21 @@ static int vhost_user_migration_done(struct vhost_dev *dev, char* mac_addr) msg.size = sizeof(msg.payload.u64); err = vhost_user_write(dev, &msg, NULL, 0); - return err; + if (reply_supported) { + if (vhost_user_read(dev, &msg) < 0) { + return 0; + } + + if (msg.request != request) { + error_report("Received unexpected msg type." + "Expected %d received %d", + request, msg.request); + return -1; + } + return msg.payload.u64 ? -1 : 0; + } else { + return err; + } } return -1; }