From patchwork Fri Jul 1 09:46:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prerna Saxena X-Patchwork-Id: 9209607 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 77165607D8 for ; Fri, 1 Jul 2016 09:47:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6671E28529 for ; Fri, 1 Jul 2016 09:47:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B3482867A; Fri, 1 Jul 2016 09:47:22 +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 91ECF28529 for ; Fri, 1 Jul 2016 09:47:21 +0000 (UTC) Received: from localhost ([::1]:60709 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIv2e-000680-Pl for patchwork-qemu-devel@patchwork.kernel.org; Fri, 01 Jul 2016 05:47:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60058) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIv25-0005yw-PN for qemu-devel@nongnu.org; Fri, 01 Jul 2016 05:46:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bIv23-0007jR-CJ for qemu-devel@nongnu.org; Fri, 01 Jul 2016 05:46:44 -0400 Received: from mail-pa0-x242.google.com ([2607:f8b0:400e:c03::242]:34081) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIv23-0007jB-0r for qemu-devel@nongnu.org; Fri, 01 Jul 2016 05:46:43 -0400 Received: by mail-pa0-x242.google.com with SMTP id us13so9389912pab.1 for ; Fri, 01 Jul 2016 02:46:42 -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=c3Pbb/sno8Lg5kBTLdB0pkL0lXdKc7OKH1d6Y4kj2S0=; b=GK+AJH4/e+YuW04i3s7RnEu+vKkwZExWohTzz9GoAK123WrcsctFd1FjEHicJItHQe yayUistTRXxKj/dIn3cm9H4pmNtuMjooPZ9jtFuiWmY0bXq3Gh1OX49VmE4kveyq2tyZ RLK6FO7KbUDiccpuL/5TWkHoiRNXAk3Vy7lSgr63RBqvOy1y5FwRggpSZoyaukeCZ1q7 KlxHMRhOfDB6BhoYXFHbV1f8EDPvkUT5PCx+vbVacHU13+4ekycjEEifwnv2Ei4G3Z7g OnLKhv+4ujHUubIaAORZDLHFjNKqswrrdieYwQRY7NdbGkul/hs3fl3oZg7NIgJiHuIy o3nQ== 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=c3Pbb/sno8Lg5kBTLdB0pkL0lXdKc7OKH1d6Y4kj2S0=; b=kv6ewfv0HQNBtzKTZuWi/9CaJ7Go/gpfKEcC1a/fnPPXgTPysk6Ynnf5luEmhl4GNK syNW4iA5VYuSpusT2a0zZULasIYJOoehwxFr3QW+HWYf4FC/xdMsAt+XasuNJfER2YTk j/lNHH2RTbehS7nKy5ubyLsmQFXgnnw4ictEj8xbFQ4sugLKpHhw7+GIFwY4IDB7s748 vjbNgOJ0I2ZEMbOZhm3sQE1mUW5h0NKszNIxX5TEKKSRyK3QSFsTe+JehWaRkmAVktNz bmotOBH8zWMIP0a/8KZAHklHgrkDjVT6msRzuX1cxCsZC0hD9YIsvh4F/TozrlRTHOLl lJNA== X-Gm-Message-State: ALyK8tL6J2zufKuVlE0PI/1yYXqW3LodQRXYxWzTM0Y2IVmkzGqZTr95lMYsYf0DpWY3RA== X-Received: by 10.67.5.37 with SMTP id cj5mr374882pad.55.1467366402089; Fri, 01 Jul 2016 02:46:42 -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 t24sm3828591pfj.75.2016.07.01.02.46.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Jul 2016 02:46:41 -0700 (PDT) From: Prerna Saxena To: qemu-devel@nongnu.org Date: Fri, 1 Jul 2016 02:46:22 -0700 Message-Id: <1467366382-7216-3-git-send-email-saxenap.ltc@gmail.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1467366382-7216-1-git-send-email-saxenap.ltc@gmail.com> References: <1467366382-7216-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::242 Subject: [Qemu-devel] [PATCH 2/2] vhost-user : Introduce a new protocol feature REPLY_ACK. 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, mst@redhat.com, marcandre.lureau@gmail.com, felipe@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 This introduces the VHOST_USER_PROTOCOL_F_REPLY_ACK. If negotiated, client applications should send a u64 payload in response to any message that contains the "need_response" bit set on the message flags. Setting the payload to "zero" indicates the command finished successfully. Likewise, setting it to "non-zero" indicates an error. Currently implemented only for SET_MEM_TABLE. Signed-off-by: Prerna Saxena --- docs/specs/vhost-user.txt | 44 ++++++++++++++++++++++++++++++++++++++++++++ hw/virtio/vhost-user.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/docs/specs/vhost-user.txt b/docs/specs/vhost-user.txt index 777c49c..26dbe71 100644 --- a/docs/specs/vhost-user.txt +++ b/docs/specs/vhost-user.txt @@ -37,6 +37,8 @@ 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 +128,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 +258,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 +469,42 @@ 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. + +With this protocol extension negotiated, the sender (QEMU) can set the newly +introduced "need_response" [Bit 3] flag to any command. This indicates that +the client MUST 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 request + * Flags: 32-bit bit field: + * Size: size of the payload ( see below) + * Payload : a u64 integer, where a non-zero value indicates a failure. + +This aids debugging the application's responses from QEMU. More +importantly, it indicates to QEMU that the requested operation has +deterministically (not) been met. Today, QEMU is expected to terminate +the main vhost-user loop upon receiving such errors. In future, qemu could +be taught to be more resilient for selective requests. + +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. +The response from the client is identical whether or not the REPLY_ACK feature +has been negotiated. diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 858a1bb..bff229e 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 }; @@ -84,6 +85,7 @@ typedef struct VhostUserMsg { #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 { @@ -107,6 +109,25 @@ static VhostUserMsg m __attribute__ ((unused)); /* The version of the protocol we support */ #define VHOST_USER_VERSION (0x1) +static int process_message_response(struct vhost_dev *dev, + VhostUserRequest request) +{ + VhostUserMsg msg; + + 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; +} + static bool ioeventfd_enabled(void) { return kvm_enabled() && kvm_eventfds_enabled(); @@ -442,11 +463,18 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev, int i, fd; size_t fd_num = 0; uint64_t features; + 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, }; + 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; ram_addr_t offset; @@ -483,6 +511,9 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev, vhost_user_write(dev, &msg, fds, fd_num); + if (reply_supported) { + return process_message_response(dev, msg.request); + } else { /* Note: It is (yet) unknown when the client application has finished * remapping the GPA. * Attempt to prevent a race by sending a command that requires a reply. @@ -490,6 +521,7 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev, vhost_user_get_features(dev, &features); return 0; + } } static int vhost_user_set_owner(struct vhost_dev *dev)