From patchwork Thu Dec 6 06:35:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 10715303 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 66D6F109C for ; Thu, 6 Dec 2018 06:38:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 475D22E7F8 for ; Thu, 6 Dec 2018 06:38:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39B962E80B; Thu, 6 Dec 2018 06:38:01 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 C37DB2E7F8 for ; Thu, 6 Dec 2018 06:38:00 +0000 (UTC) Received: from localhost ([::1]:39093 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUnIN-0002Hx-6U for patchwork-qemu-devel@patchwork.kernel.org; Thu, 06 Dec 2018 01:37:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUnH4-0001Js-IJ for qemu-devel@nongnu.org; Thu, 06 Dec 2018 01:36:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gUnH1-0003Es-PW for qemu-devel@nongnu.org; Thu, 06 Dec 2018 01:36:38 -0500 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:34113) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gUnH1-0003BZ-G7 for qemu-devel@nongnu.org; Thu, 06 Dec 2018 01:36:35 -0500 Received: by mail-pg1-x544.google.com with SMTP id 17so10208605pgg.1 for ; Wed, 05 Dec 2018 22:36:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MV5KnfjMHiDJvr3z6fKJ2mUgqVgBbW4RRnCmmfVxATA=; b=CJnrXU318CUp6y0ZC+hvq8ss9Aga6WUtR9r6AXBPKkd+iSRn2BVdrAhmif0Fa18N4K qXCdh5yL5bDkErW93u3DmDNeWb5p+yO6cEnPQb/eIBi4j8KKxVo+e1wpnGTwnLWFxKqm mVGZKllnbXkKKZkTxdL3W+P4S0NJ8ldZIIo6ngNDOUaf9gJUVf19L7JEc8ux/ACvVwAq Ql0BjRQh9fiD4Hjz91jkG9AH6VC3q7ghwt28U5Syk0QuAdWSUuVzLCgq5mMgyfCkRur5 QrMSX/O8mY2EEvCsR7tidOrg7jRxs6A0KnljFFClybJ3NgRbzFtOxs2QMvKDJJ3x9uLd ndjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MV5KnfjMHiDJvr3z6fKJ2mUgqVgBbW4RRnCmmfVxATA=; b=sztX9AF63GIU6KJi3KQ/x+y5ED9EMYBKawLs4gDIbwb7Yat19rpLx4efQEk0JlJKDm 8s+BILspLjYC+7LDUa/EvmK38DpjRgcuHbPOXn1X7TWBGfXCrWT9I0TDByZYA9GTlVpm VCaHdl+yJnIOUWWy2ZxtGt4vNRZxlPuACsZBxIXWsjpeJTGpY/DNiP7ROFICRZHuDOvr H2n3ooyrT0vJ2wb0TFftxsw/zInmohzKOJlQ7dYR0BgCxyaxAYCOOdo5XwBuaxkX4PI7 gEFS4QHRSODGITEV8NDvYzUXvvQ+ZkYp1QU0sRpmwxK3YQV8Ce4XRBTKg1QbUIWS5IbJ /1fw== X-Gm-Message-State: AA+aEWarBsrvNdDU22ftB/b2ELFHZVZ6f6IqmGx+a/xuQqmfQpmFRURN aEa1wsA7xDqzK+HEg3c8Fi3Rorhd7UA= X-Google-Smtp-Source: AFSGD/UDkPcPsb7IGDBXm0PbJ3A7PxFS+70L9rbp7u1HDobivxiTktnS1fO4StNLTNaFPU7499tFKQ== X-Received: by 2002:a62:7f94:: with SMTP id a142mr27604606pfd.96.1544078194499; Wed, 05 Dec 2018 22:36:34 -0800 (PST) Received: from yongji-Ubuntu.internal.baidu.com ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id x186sm26175249pfb.59.2018.12.05.22.36.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Dec 2018 22:36:34 -0800 (PST) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, marcandre.lureau@redhat.com Date: Thu, 6 Dec 2018 14:35:47 +0800 Message-Id: <20181206063552.6701-2-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181206063552.6701-1-xieyongji@baidu.com> References: <20181206063552.6701-1-xieyongji@baidu.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::544 Subject: [Qemu-devel] [PATCH for-4.0 1/6] char-socket: Enable "wait" option for client mode 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: nixun@baidu.com, qemu-devel@nongnu.org, lilin24@baidu.com, zhangyu31@baidu.com, chaiwen@baidu.com, Xie Yongji Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Xie Yongji Now we attempt to connect asynchronously for "reconnect socket" during open(). But vhost-user device prefer a connected socket during initialization. That means we may still need to support sync connection during open() for the "reconnect socket". Signed-off-by: Xie Yongji Signed-off-by: Zhang Yu --- chardev/char-socket.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index eaa8e8b68f..f2819d52e7 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -1072,7 +1072,7 @@ static void qmp_chardev_open_socket(Chardev *chr, s->reconnect_time = reconnect; } - if (s->reconnect_time) { + if (s->reconnect_time && !is_waitconnect) { tcp_chr_connect_async(chr); } else { if (s->is_listen) { @@ -1120,7 +1120,8 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend, Error **errp) { bool is_listen = qemu_opt_get_bool(opts, "server", false); - bool is_waitconnect = is_listen && qemu_opt_get_bool(opts, "wait", true); + bool is_waitconnect = is_listen ? qemu_opt_get_bool(opts, "wait", true) : + qemu_opt_get_bool(opts, "wait", false); bool is_telnet = qemu_opt_get_bool(opts, "telnet", false); bool is_tn3270 = qemu_opt_get_bool(opts, "tn3270", false); bool is_websock = qemu_opt_get_bool(opts, "websocket", false); From patchwork Thu Dec 6 06:35:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 10715311 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7B53113BF for ; Thu, 6 Dec 2018 06:40:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 679BF2E1D4 for ; Thu, 6 Dec 2018 06:40:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BB332E357; Thu, 6 Dec 2018 06:40:53 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 B5F732E1D4 for ; Thu, 6 Dec 2018 06:40:52 +0000 (UTC) Received: from localhost ([::1]:39110 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUnL9-0004wx-VU for patchwork-qemu-devel@patchwork.kernel.org; Thu, 06 Dec 2018 01:40:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52805) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUnHJ-0001Sr-82 for qemu-devel@nongnu.org; Thu, 06 Dec 2018 01:36:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gUnHB-0003Os-LM for qemu-devel@nongnu.org; Thu, 06 Dec 2018 01:36:51 -0500 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:46198) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gUnH9-0003MD-Hw for qemu-devel@nongnu.org; Thu, 06 Dec 2018 01:36:45 -0500 Received: by mail-pg1-x544.google.com with SMTP id w7so10179284pgp.13 for ; Wed, 05 Dec 2018 22:36:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=R8PT06pUE8dn1kFgVY/VcsbF2I2WIcg1CFzPd6hORKs=; b=HYDg3s0ott3FOOANmNqmUBMkE4p7+F9fKma7LNDwrgsz5EncOYFMnvlxNTKE8xxrEu 4m0pvH+NNDCz0iTdmmfCMb3XUZVmVGZgAH/NdMFK8DklQVFzXJNIF/KEYBlYDBt1+i3N qHZhzSMdMCsT1flNfEsIT8/afoqiSbNbGKQ1oosMCRH2scTRyQcxTrcj9heoxAjQYvLE Xul9wQ/KeIHKiDdAVkj5f1MLGHRT57h1CAIVO+V1RlM4Kk+Ls6t5HgEWIEWQMWWgDshW 8Mdfu2KOaug2EAd0mxlBbM0RJ+WbtsNU+wKa6pGPHQd5nrlnHY2FViktc7wZRcERVkf8 oTtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=R8PT06pUE8dn1kFgVY/VcsbF2I2WIcg1CFzPd6hORKs=; b=Sunuft/FOFda1PVXFr1bZwtVWyxTRHuaY8fw+GRsKfxYv37F5xURTAfoIRPs2Dzfh9 8g7dIc0vRI3FUN8AN2MIrnM+7JwICP8GvP9NG6GKVzq5baCHo3wZ0rWfB0QIj+I0TTTU MIfWE42kyJ/YyDkuUUGQ3o0kJCOyxZfVHXDzXrRwpFJbNQPEdLIKz3QIIgRnbjCW6RIi 9+eP26O+mmDE//PMKsSHOuzfTmEBMejDRLyl25UBStMTZ9DWa4ofN4ZKt5lIuBgX+WpQ /D0DixkGCpng/mt5+B4NY6Ton2S5GSyKSuVDRiVkwKtcOAsNLHl9S1Xb51MjOTO/Xbnc WZDA== X-Gm-Message-State: AA+aEWZNVpwbJteOuO5n4wHdhVZvvfEQmDj0Q5bi/YSsqsCdEsGoXdUk +4Vf7WWNKEM6469zxsYZMTM= X-Google-Smtp-Source: AFSGD/VqmpF44YSesIdOVq/5P84B04IiibEwdBKJzlhNlDw/G3Wysms8Vo/wBg8lfphhlpPor6i/2A== X-Received: by 2002:a63:6ecf:: with SMTP id j198mr23484012pgc.3.1544078201664; Wed, 05 Dec 2018 22:36:41 -0800 (PST) Received: from yongji-Ubuntu.internal.baidu.com ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id x186sm26175249pfb.59.2018.12.05.22.36.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Dec 2018 22:36:41 -0800 (PST) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, marcandre.lureau@redhat.com Date: Thu, 6 Dec 2018 14:35:48 +0800 Message-Id: <20181206063552.6701-3-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181206063552.6701-1-xieyongji@baidu.com> References: <20181206063552.6701-1-xieyongji@baidu.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::544 Subject: [Qemu-devel] [PATCH for-4.0 2/6] vhost-user: Add shared memory to record inflight I/O 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: nixun@baidu.com, qemu-devel@nongnu.org, lilin24@baidu.com, zhangyu31@baidu.com, chaiwen@baidu.com, Xie Yongji Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Xie Yongji This introduces a new message VHOST_USER_SET_VRING_INFLIGHT to support offering shared memory to backend to record its inflight I/O. With this new message, the backend is able to restart without missing I/O which would cause I/O hung for block device. Signed-off-by: Xie Yongji Signed-off-by: Chai Wen Signed-off-by: Zhang Yu --- hw/virtio/vhost-user.c | 69 +++++++++++++++++++++++++++++++ hw/virtio/vhost.c | 8 ++++ include/hw/virtio/vhost-backend.h | 4 ++ include/hw/virtio/vhost-user.h | 8 ++++ 4 files changed, 89 insertions(+) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index e09bed0e4a..4c0e64891d 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -19,6 +19,7 @@ #include "sysemu/kvm.h" #include "qemu/error-report.h" #include "qemu/sockets.h" +#include "qemu/memfd.h" #include "sysemu/cryptodev.h" #include "migration/migration.h" #include "migration/postcopy-ram.h" @@ -52,6 +53,7 @@ enum VhostUserProtocolFeature { VHOST_USER_PROTOCOL_F_CONFIG = 9, VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD = 10, VHOST_USER_PROTOCOL_F_HOST_NOTIFIER = 11, + VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD = 12, VHOST_USER_PROTOCOL_F_MAX }; @@ -89,6 +91,7 @@ typedef enum VhostUserRequest { VHOST_USER_POSTCOPY_ADVISE = 28, VHOST_USER_POSTCOPY_LISTEN = 29, VHOST_USER_POSTCOPY_END = 30, + VHOST_USER_SET_VRING_INFLIGHT = 31, VHOST_USER_MAX } VhostUserRequest; @@ -147,6 +150,11 @@ typedef struct VhostUserVringArea { uint64_t offset; } VhostUserVringArea; +typedef struct VhostUserVringInflight { + uint32_t size; + uint32_t idx; +} VhostUserVringInflight; + typedef struct { VhostUserRequest request; @@ -169,6 +177,7 @@ typedef union { VhostUserConfig config; VhostUserCryptoSession session; VhostUserVringArea area; + VhostUserVringInflight inflight; } VhostUserPayload; typedef struct VhostUserMsg { @@ -1739,6 +1748,58 @@ static bool vhost_user_mem_section_filter(struct vhost_dev *dev, return result; } +static int vhost_user_set_vring_inflight(struct vhost_dev *dev, int idx) +{ + struct vhost_user *u = dev->opaque; + + if (!virtio_has_feature(dev->protocol_features, + VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD)) { + return 0; + } + + if (!u->user->inflight[idx].addr) { + Error *err = NULL; + + u->user->inflight[idx].size = qemu_real_host_page_size; + u->user->inflight[idx].addr = qemu_memfd_alloc("vhost-inflight", + u->user->inflight[idx].size, + F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL, + &u->user->inflight[idx].fd, &err); + if (err) { + error_report_err(err); + u->user->inflight[idx].addr = NULL; + return -1; + } + } + + VhostUserMsg msg = { + .hdr.request = VHOST_USER_SET_VRING_INFLIGHT, + .hdr.flags = VHOST_USER_VERSION, + .payload.inflight.size = u->user->inflight[idx].size, + .payload.inflight.idx = idx, + .hdr.size = sizeof(msg.payload.inflight), + }; + + if (vhost_user_write(dev, &msg, &u->user->inflight[idx].fd, 1) < 0) { + return -1; + } + + return 0; +} + +void vhost_user_inflight_reset(VhostUserState *user) +{ + int i; + + for (i = 0; i < VIRTIO_QUEUE_MAX; i++) { + if (!user->inflight[i].addr) { + continue; + } + + memset(user->inflight[i].addr, 0, user->inflight[i].size); + } +} + VhostUserState *vhost_user_init(void) { VhostUserState *user = g_new0(struct VhostUserState, 1); @@ -1756,6 +1817,13 @@ void vhost_user_cleanup(VhostUserState *user) munmap(user->notifier[i].addr, qemu_real_host_page_size); user->notifier[i].addr = NULL; } + + if (user->inflight[i].addr) { + munmap(user->inflight[i].addr, user->inflight[i].size); + user->inflight[i].addr = NULL; + close(user->inflight[i].fd); + user->inflight[i].fd = -1; + } } } @@ -1790,4 +1858,5 @@ const VhostOps user_ops = { .vhost_crypto_create_session = vhost_user_crypto_create_session, .vhost_crypto_close_session = vhost_user_crypto_close_session, .vhost_backend_mem_section_filter = vhost_user_mem_section_filter, + .vhost_set_vring_inflight = vhost_user_set_vring_inflight, }; diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 569c4053ea..2ca7b4e841 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -973,6 +973,14 @@ static int vhost_virtqueue_start(struct vhost_dev *dev, return -errno; } + if (dev->vhost_ops->vhost_set_vring_inflight) { + r = dev->vhost_ops->vhost_set_vring_inflight(dev, vhost_vq_index); + if (r) { + VHOST_OPS_DEBUG("vhost_set_vring_inflight failed"); + return -errno; + } + } + state.num = virtio_queue_get_last_avail_idx(vdev, idx); r = dev->vhost_ops->vhost_set_vring_base(dev, &state); if (r) { diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h index 81283ec50f..8110e09089 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -104,6 +104,9 @@ typedef int (*vhost_crypto_close_session_op)(struct vhost_dev *dev, typedef bool (*vhost_backend_mem_section_filter_op)(struct vhost_dev *dev, MemoryRegionSection *section); +typedef int (*vhost_set_vring_inflight_op)(struct vhost_dev *dev, + int idx); + typedef struct VhostOps { VhostBackendType backend_type; vhost_backend_init vhost_backend_init; @@ -142,6 +145,7 @@ typedef struct VhostOps { vhost_crypto_create_session_op vhost_crypto_create_session; vhost_crypto_close_session_op vhost_crypto_close_session; vhost_backend_mem_section_filter_op vhost_backend_mem_section_filter; + vhost_set_vring_inflight_op vhost_set_vring_inflight; } VhostOps; extern const VhostOps user_ops; diff --git a/include/hw/virtio/vhost-user.h b/include/hw/virtio/vhost-user.h index fd660393a0..ff13433153 100644 --- a/include/hw/virtio/vhost-user.h +++ b/include/hw/virtio/vhost-user.h @@ -17,11 +17,19 @@ typedef struct VhostUserHostNotifier { bool set; } VhostUserHostNotifier; +typedef struct VhostUserInflight { + void *addr; + uint32_t size; + int fd; +} VhostUserInflight; + typedef struct VhostUserState { CharBackend *chr; VhostUserHostNotifier notifier[VIRTIO_QUEUE_MAX]; + VhostUserInflight inflight[VIRTIO_QUEUE_MAX]; } VhostUserState; +void vhost_user_inflight_reset(VhostUserState *user); VhostUserState *vhost_user_init(void); void vhost_user_cleanup(VhostUserState *user); From patchwork Thu Dec 6 06:35:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 10715313 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1DEF413AF for ; Thu, 6 Dec 2018 06:40:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C77E2E1D4 for ; Thu, 6 Dec 2018 06:40:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00C912E357; Thu, 6 Dec 2018 06:40:53 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 7EDB82E28D for ; Thu, 6 Dec 2018 06:40:53 +0000 (UTC) Received: from localhost ([::1]:39111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUnLA-0004yP-NY for patchwork-qemu-devel@patchwork.kernel.org; Thu, 06 Dec 2018 01:40:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52810) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUnHJ-0001Ss-7z for qemu-devel@nongnu.org; Thu, 06 Dec 2018 01:36:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gUnHF-0003TT-A0 for qemu-devel@nongnu.org; Thu, 06 Dec 2018 01:36:51 -0500 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:38351) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gUnHE-0003Pq-Os for qemu-devel@nongnu.org; Thu, 06 Dec 2018 01:36:48 -0500 Received: by mail-pg1-x542.google.com with SMTP id g189so10189250pgc.5 for ; Wed, 05 Dec 2018 22:36:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XKl4V81WAbYlKQdyvx2f7AmT9JieubeQLT/wGHLl3FU=; b=ZwP6bI6ksSCLQbTJdW+LHrq3Mfuiwqeivi/4R4uPYZdFKpbMD4jquJqa5Q7xkxlwSL OEtEcQWVtpTA80r9Trjplc9JzUf4w0x81D+8l7Rf/1J/7qzEU6ZsWPuf8LHlKhtyNbEG x4W3C+LFg13/c4jihEbvhgCWNUpmMv0FNfsPw6BUr1h3gcbqiITllaa3wBKsUViaumTX reSm0ldnDPXHUTs9CiVpxouCRNpqyb6sbfb9tPQELT5xkIGUjs+rmtFBX4qrq0faf6kq tQh3wDytL7XiDFUB9pfyI6ewvBflVE+Tv2vr+VpQ+H1EspUrxwucJazRNtTF2PWdBD6r YCmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XKl4V81WAbYlKQdyvx2f7AmT9JieubeQLT/wGHLl3FU=; b=IsoPx2h9BdAg7OEICJw0Heb6Q+NVz3RZkrVnZX5msMqG8KqEgEhyH3sW4aMhKaCGzD z4BSrKLjrROFeQaxdMP3YdoriGW0xl0DdFAuKTOCl55I1GYBZgiaiidRXxKYXWjOwuhu aEOZQZMnYF6KULyLfNo40RRm+EVt4KWte1w74EZNplbXlBR7FO0/DOR52SE0RNj6cgXj 9cGz2AtZUPr8GFLJkvb8f1Ch5OP96dQNgBcE4O0B0cyAp3AFhVxTnrwSd7lMKnNPXrmz pBEJOrLdTXDEmzgXTKwPvZ3visiZkOkJTl3LmLyv6YnM2CYUn9RaG00ddOhvu9PL4vYZ jPvg== X-Gm-Message-State: AA+aEWbsKzGiiLOfcqrBzsH3HxDePfrKyS5vXmxtnCi9dc+skBnSlvod fRwjcltVq3MK8MU5o4Ti5KfFuBal0D0= X-Google-Smtp-Source: AFSGD/UTvSvU+IpQyd29yuwQhtIUJ3F6LV1Ud7f6guM1uBNDa4QY/yb2JMfVWroUwIrCiWAMlVnWEQ== X-Received: by 2002:a63:b17:: with SMTP id 23mr23290622pgl.423.1544078205596; Wed, 05 Dec 2018 22:36:45 -0800 (PST) Received: from yongji-Ubuntu.internal.baidu.com ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id x186sm26175249pfb.59.2018.12.05.22.36.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Dec 2018 22:36:45 -0800 (PST) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, marcandre.lureau@redhat.com Date: Thu, 6 Dec 2018 14:35:49 +0800 Message-Id: <20181206063552.6701-4-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181206063552.6701-1-xieyongji@baidu.com> References: <20181206063552.6701-1-xieyongji@baidu.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH for-4.0 3/6] libvhost-user: Introduce vu_queue_map_desc() 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: nixun@baidu.com, qemu-devel@nongnu.org, lilin24@baidu.com, zhangyu31@baidu.com, chaiwen@baidu.com, Xie Yongji Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Xie Yongji Introduce vu_queue_map_desc() which should be independent with vu_queue_pop(); Signed-off-by: Xie Yongji Signed-off-by: Zhang Yu Reviewed-by: Marc-André Lureau --- contrib/libvhost-user/libvhost-user.c | 86 +++++++++++++++------------ 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/libvhost-user.c index a6b46cdc03..4432bd8bb4 100644 --- a/contrib/libvhost-user/libvhost-user.c +++ b/contrib/libvhost-user/libvhost-user.c @@ -1853,49 +1853,20 @@ virtqueue_alloc_element(size_t sz, return elem; } -void * -vu_queue_pop(VuDev *dev, VuVirtq *vq, size_t sz) +static void * +vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned int idx, size_t sz) { - unsigned int i, head, max, desc_len; + struct vring_desc *desc = vq->vring.desc; uint64_t desc_addr, read_len; + unsigned int desc_len; + unsigned int max = vq->vring.num; + unsigned int i = idx; VuVirtqElement *elem; - unsigned out_num, in_num; + unsigned int out_num = 0, in_num = 0; struct iovec iov[VIRTQUEUE_MAX_SIZE]; struct vring_desc desc_buf[VIRTQUEUE_MAX_SIZE]; - struct vring_desc *desc; int rc; - if (unlikely(dev->broken) || - unlikely(!vq->vring.avail)) { - return NULL; - } - - if (vu_queue_empty(dev, vq)) { - return NULL; - } - /* Needed after virtio_queue_empty(), see comment in - * virtqueue_num_heads(). */ - smp_rmb(); - - /* When we start there are none of either input nor output. */ - out_num = in_num = 0; - - max = vq->vring.num; - if (vq->inuse >= vq->vring.num) { - vu_panic(dev, "Virtqueue size exceeded"); - return NULL; - } - - if (!virtqueue_get_head(dev, vq, vq->last_avail_idx++, &head)) { - return NULL; - } - - if (vu_has_feature(dev, VIRTIO_RING_F_EVENT_IDX)) { - vring_set_avail_event(vq, vq->last_avail_idx); - } - - i = head; - desc = vq->vring.desc; if (desc[i].flags & VRING_DESC_F_INDIRECT) { if (desc[i].len % sizeof(struct vring_desc)) { vu_panic(dev, "Invalid size for indirect buffer table"); @@ -1947,12 +1918,13 @@ vu_queue_pop(VuDev *dev, VuVirtq *vq, size_t sz) } while (rc == VIRTQUEUE_READ_DESC_MORE); if (rc == VIRTQUEUE_READ_DESC_ERROR) { + vu_panic(dev, "read descriptor error"); return NULL; } /* Now copy what we have collected and mapped */ elem = virtqueue_alloc_element(sz, out_num, in_num); - elem->index = head; + elem->index = idx; for (i = 0; i < out_num; i++) { elem->out_sg[i] = iov[i]; } @@ -1960,6 +1932,46 @@ vu_queue_pop(VuDev *dev, VuVirtq *vq, size_t sz) elem->in_sg[i] = iov[out_num + i]; } + return elem; +} + +void * +vu_queue_pop(VuDev *dev, VuVirtq *vq, size_t sz) +{ + unsigned int head; + VuVirtqElement *elem; + + if (unlikely(dev->broken) || + unlikely(!vq->vring.avail)) { + return NULL; + } + + if (vu_queue_empty(dev, vq)) { + return NULL; + } + /* Needed after virtio_queue_empty(), see comment in + * virtqueue_num_heads(). */ + smp_rmb(); + + if (vq->inuse >= vq->vring.num) { + vu_panic(dev, "Virtqueue size exceeded"); + return NULL; + } + + if (!virtqueue_get_head(dev, vq, vq->last_avail_idx++, &head)) { + return NULL; + } + + if (vu_has_feature(dev, VIRTIO_RING_F_EVENT_IDX)) { + vring_set_avail_event(vq, vq->last_avail_idx); + } + + elem = vu_queue_map_desc(dev, vq, head, sz); + + if (!elem) { + return NULL; + } + vq->inuse++; return elem; From patchwork Thu Dec 6 06:35:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 10715307 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 163F718A7 for ; Thu, 6 Dec 2018 06:38:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0380F2E809 for ; Thu, 6 Dec 2018 06:38:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EAF522E814; Thu, 6 Dec 2018 06:38:34 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 4DBA22E809 for ; Thu, 6 Dec 2018 06:38:34 +0000 (UTC) Received: from localhost ([::1]:39095 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUnIv-0002mr-CJ for patchwork-qemu-devel@patchwork.kernel.org; Thu, 06 Dec 2018 01:38:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52875) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUnHR-0001Xi-8V for qemu-devel@nongnu.org; Thu, 06 Dec 2018 01:37:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gUnHL-0003Yu-5p for qemu-devel@nongnu.org; Thu, 06 Dec 2018 01:36:59 -0500 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:35435) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gUnHH-0003Tm-AU for qemu-devel@nongnu.org; Thu, 06 Dec 2018 01:36:53 -0500 Received: by mail-pg1-x543.google.com with SMTP id s198so10211068pgs.2 for ; Wed, 05 Dec 2018 22:36:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bW+YSFxiflf4ZGeT27q2UEWAxdOJmnquUgmkkLRZ6rk=; b=gW53+VlsYJs10FhaNFXzhW/mG1Ahi/8/BFgffMJ2MVpXGUp0Q6qdOYqifi+7KCA0xN BYYYxD1u+ac4nW+1WoqyPGfr1srzSdW9bm6+CgDSPx6sx+YjaW46d6lVhhuy9KNXC2b1 5wV+AaJ7MTqzN3L3J9cSNSipbrIJU4W9uKR4EAmiNcDmEYz6d2Fx1I4hv/nNvJ+oGzyr BvK/hnFmjbQUhP3c7Iu9OHydmGc7gaNkgbcdDMipOIjHXouX7x765yZTCU4yVp6kYo79 mCZab9LJRAqLhHZM+3gVfGNrdRlL0QkyJquJ0d0JkmJ3Az5l065zHwNW9RR9UyP2er3q crOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bW+YSFxiflf4ZGeT27q2UEWAxdOJmnquUgmkkLRZ6rk=; b=g02acUs4lcFb2TpSs+PVn1kA7qGesSj+OzANZfn85oJz6HuHoBoRFrBiFIryXfmTvR Tp3xJ8eYlIbETHDmBVA/HHtz9mzSp3ayS+dj0RkiHzoeP4NlY8GOXXDhtrQeI/8rAl/I EClFq45FT7u8jXMnhHQeNYGL+vbFS7Rh2vzmllU5h2/lohPTroT/Ac9NtxeWxG1t7vqg iC0NRKlSrzQGG0jBhX+DS0wckNRDDixpKCmcyzZOHjtk5q3zK4HwYktngqYWW8oKGEaU 8pm7tZGdc/q6G5D6nslNOC99/91KzSq1/lEyQPb/k9tOkDX6/6YK/OJa6cnERuAMJ6Mv /Ehg== X-Gm-Message-State: AA+aEWYypT+6z7sL50R/zFbf+XsQlHDU7H8ZqKqys5Dfaycj5aoXL7Ev 9AOmcm82lbEDgGBP4lgR3Ko= X-Google-Smtp-Source: AFSGD/VhKJ5m8ju/yjvgkYtHHImuPmGtQlEBLAjlYzDlzOGqU883nlHRprPA8rvj+ANJF3ApWav06w== X-Received: by 2002:a63:e615:: with SMTP id g21mr23463584pgh.290.1544078209248; Wed, 05 Dec 2018 22:36:49 -0800 (PST) Received: from yongji-Ubuntu.internal.baidu.com ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id x186sm26175249pfb.59.2018.12.05.22.36.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Dec 2018 22:36:48 -0800 (PST) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, marcandre.lureau@redhat.com Date: Thu, 6 Dec 2018 14:35:50 +0800 Message-Id: <20181206063552.6701-5-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181206063552.6701-1-xieyongji@baidu.com> References: <20181206063552.6701-1-xieyongji@baidu.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::543 Subject: [Qemu-devel] [PATCH for-4.0 4/6] libvhost-user: Support recording inflight I/O in shared memory 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: nixun@baidu.com, qemu-devel@nongnu.org, lilin24@baidu.com, zhangyu31@baidu.com, chaiwen@baidu.com, Xie Yongji Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Xie Yongji This patch adds support for VHOST_USER_SET_VRING_INFLIGHT message. Now we maintain a "bitmap" of all descriptors in the shared memory for each queue. Then set it in vu_queue_pop() and clear it in vu_queue_push(); Signed-off-by: Xie Yongji Signed-off-by: Zhang Yu --- contrib/libvhost-user/libvhost-user.c | 129 ++++++++++++++++++++++++++ contrib/libvhost-user/libvhost-user.h | 19 ++++ 2 files changed, 148 insertions(+) diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/libvhost-user.c index 4432bd8bb4..38ef1f5898 100644 --- a/contrib/libvhost-user/libvhost-user.c +++ b/contrib/libvhost-user/libvhost-user.c @@ -100,6 +100,7 @@ vu_request_to_string(unsigned int req) REQ(VHOST_USER_POSTCOPY_ADVISE), REQ(VHOST_USER_POSTCOPY_LISTEN), REQ(VHOST_USER_POSTCOPY_END), + REQ(VHOST_USER_SET_VRING_INFLIGHT), REQ(VHOST_USER_MAX), }; #undef REQ @@ -890,6 +891,41 @@ vu_check_queue_msg_file(VuDev *dev, VhostUserMsg *vmsg) return true; } +static int +vu_check_queue_inflights(VuDev *dev, VuVirtq *vq) +{ + int i = 0; + + if ((dev->protocol_features & + VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD) == 0) { + return 0; + } + + if (unlikely(!vq->inflight.addr)) { + return -1; + } + + vq->used_idx = vq->vring.used->idx; + vq->inflight_num = 0; + for (i = 0; i < vq->vring.num; i++) { + if (vq->inflight.addr[i] == 0) { + continue; + } + + vq->inflight_desc[vq->inflight_num++] = i; + vq->inuse++; + } + vq->shadow_avail_idx = vq->last_avail_idx = vq->inuse + vq->used_idx; + + /* in case of I/O hang after reconnecting */ + if (eventfd_write(vq->kick_fd, 1) || + eventfd_write(vq->call_fd, 1)) { + return -1; + } + + return 0; +} + static bool vu_set_vring_kick_exec(VuDev *dev, VhostUserMsg *vmsg) { @@ -925,6 +961,10 @@ vu_set_vring_kick_exec(VuDev *dev, VhostUserMsg *vmsg) dev->vq[index].kick_fd, index); } + if (vu_check_queue_inflights(dev, &dev->vq[index])) { + vu_panic(dev, "Failed to check inflights for vq: %d\n", index); + } + return false; } @@ -1215,6 +1255,44 @@ vu_set_postcopy_end(VuDev *dev, VhostUserMsg *vmsg) return true; } +static bool +vu_set_vring_inflight(VuDev *dev, VhostUserMsg *vmsg) +{ + int fd; + uint32_t size, idx; + void *rc; + + if (vmsg->fd_num != 1 || + vmsg->size != sizeof(vmsg->payload.inflight)) { + vu_panic(dev, "Invalid vring_inflight message size:%d fds:%d", + vmsg->size, vmsg->fd_num); + return false; + } + + fd = vmsg->fds[0]; + idx = vmsg->payload.inflight.idx; + size = vmsg->payload.inflight.size; + DPRINT("vring_inflight idx: %"PRId32"\n", idx); + DPRINT("vring_inflight size: %"PRId32"\n", size); + + rc = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + + close(fd); + + if (rc == MAP_FAILED) { + vu_panic(dev, "vring_inflight mmap error: %s", strerror(errno)); + return false; + } + + if (dev->vq[idx].inflight.addr) { + munmap(dev->vq[idx].inflight.addr, dev->vq[idx].inflight.size); + } + dev->vq[idx].inflight.addr = (char *)rc; + dev->vq[idx].inflight.size = size; + + return false; +} + static bool vu_process_message(VuDev *dev, VhostUserMsg *vmsg) { @@ -1292,6 +1370,8 @@ vu_process_message(VuDev *dev, VhostUserMsg *vmsg) return vu_set_postcopy_listen(dev, vmsg); case VHOST_USER_POSTCOPY_END: return vu_set_postcopy_end(dev, vmsg); + case VHOST_USER_SET_VRING_INFLIGHT: + return vu_set_vring_inflight(dev, vmsg); default: vmsg_close_fds(vmsg); vu_panic(dev, "Unhandled request: %d", vmsg->request); @@ -1359,6 +1439,11 @@ vu_deinit(VuDev *dev) close(vq->err_fd); vq->err_fd = -1; } + + if (vq->inflight.addr) { + munmap(vq->inflight.addr, vq->inflight.size); + vq->inflight.addr = NULL; + } } @@ -1935,9 +2020,44 @@ vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned int idx, size_t sz) return elem; } +static int +vu_queue_inflight_get(VuDev *dev, VuVirtq *vq, int desc_idx) +{ + if ((dev->protocol_features & + VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD) == 0) { + return 0; + } + + if (unlikely(!vq->inflight.addr)) { + return -1; + } + + vq->inflight.addr[desc_idx] = 1; + + return 0; +} + +static int +vu_queue_inflight_put(VuDev *dev, VuVirtq *vq, int desc_idx) +{ + if ((dev->protocol_features & + VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD) == 0) { + return 0; + } + + if (unlikely(!vq->inflight.addr)) { + return -1; + } + + vq->inflight.addr[desc_idx] = 0; + + return 0; +} + void * vu_queue_pop(VuDev *dev, VuVirtq *vq, size_t sz) { + int i; unsigned int head; VuVirtqElement *elem; @@ -1946,6 +2066,12 @@ vu_queue_pop(VuDev *dev, VuVirtq *vq, size_t sz) return NULL; } + if (unlikely(vq->inflight_num > 0)) { + i = (--vq->inflight_num); + elem = vu_queue_map_desc(dev, vq, vq->inflight_desc[i], sz); + return elem; + } + if (vu_queue_empty(dev, vq)) { return NULL; } @@ -1974,6 +2100,8 @@ vu_queue_pop(VuDev *dev, VuVirtq *vq, size_t sz) vq->inuse++; + vu_queue_inflight_get(dev, vq, head); + return elem; } @@ -2119,4 +2247,5 @@ vu_queue_push(VuDev *dev, VuVirtq *vq, { vu_queue_fill(dev, vq, elem, len, 0); vu_queue_flush(dev, vq, 1); + vu_queue_inflight_put(dev, vq, elem->index); } diff --git a/contrib/libvhost-user/libvhost-user.h b/contrib/libvhost-user/libvhost-user.h index 4aa55b4d2d..2b0d14fd41 100644 --- a/contrib/libvhost-user/libvhost-user.h +++ b/contrib/libvhost-user/libvhost-user.h @@ -53,6 +53,7 @@ enum VhostUserProtocolFeature { VHOST_USER_PROTOCOL_F_CONFIG = 9, VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD = 10, VHOST_USER_PROTOCOL_F_HOST_NOTIFIER = 11, + VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD = 12, VHOST_USER_PROTOCOL_F_MAX }; @@ -91,6 +92,7 @@ typedef enum VhostUserRequest { VHOST_USER_POSTCOPY_ADVISE = 28, VHOST_USER_POSTCOPY_LISTEN = 29, VHOST_USER_POSTCOPY_END = 30, + VHOST_USER_SET_VRING_INFLIGHT = 31, VHOST_USER_MAX } VhostUserRequest; @@ -138,6 +140,11 @@ typedef struct VhostUserVringArea { uint64_t offset; } VhostUserVringArea; +typedef struct VhostUserVringInflight { + uint32_t size; + uint32_t idx; +} VhostUserVringInflight; + #if defined(_WIN32) # define VU_PACKED __attribute__((gcc_struct, packed)) #else @@ -163,6 +170,7 @@ typedef struct VhostUserMsg { VhostUserLog log; VhostUserConfig config; VhostUserVringArea area; + VhostUserVringInflight inflight; } payload; int fds[VHOST_MEMORY_MAX_NREGIONS]; @@ -234,9 +242,20 @@ typedef struct VuRing { uint32_t flags; } VuRing; +typedef struct VuInflight { + char *addr; + uint32_t size; +} VuInflight; + typedef struct VuVirtq { VuRing vring; + VuInflight inflight; + + uint16_t inflight_desc[VIRTQUEUE_MAX_SIZE]; + + uint16_t inflight_num; + /* Next head to pop */ uint16_t last_avail_idx; From patchwork Thu Dec 6 06:35:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 10715309 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DD91A18A7 for ; Thu, 6 Dec 2018 06:38:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B488E29305 for ; Thu, 6 Dec 2018 06:38:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4746291BF; Thu, 6 Dec 2018 06:38:37 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 B8E902852B for ; Thu, 6 Dec 2018 06:38:36 +0000 (UTC) Received: from localhost ([::1]:39096 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUnIx-0002pV-UH for patchwork-qemu-devel@patchwork.kernel.org; Thu, 06 Dec 2018 01:38:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52880) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUnHR-0001Xn-Aj for qemu-devel@nongnu.org; Thu, 06 Dec 2018 01:37:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gUnHP-0003bB-9J for qemu-devel@nongnu.org; Thu, 06 Dec 2018 01:37:01 -0500 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:35574) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gUnHL-0003YS-7O for qemu-devel@nongnu.org; Thu, 06 Dec 2018 01:36:57 -0500 Received: by mail-pl1-x641.google.com with SMTP id p8so11325221plo.2 for ; Wed, 05 Dec 2018 22:36:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dU/eUAUX7IkjZsgttuh1Gp6IYyyjhsKSGjoHIekrBvA=; b=VthW2pEyM0HU8hwrtNwVAdGkXDDAHPEjosPZzZHZzGymPlWjr7id4xwOVj7VFRnovJ NuhvpkVnDKfQyzskO5Rc4vXZHt1kPVfcor3XAwbW22I5/DUDRrbfePvGbh9WAGO/FqQN 0jTp8D5KPRZ2dxjUgX+apXkA+Ahq9ymKXDpvTfSAS2ex4MqOogFWpwt6leXjGEXkoGMF 4BTwCU8rGQzzYk2B6jUmBJKpy6wX+M3DKiKrh4i55YQ+PffX2pCHBxOTB08qDOSVpRg7 k7EuKS227C3b9mcy7VBFALj8mSw2Kj0GUU3086LFrY7hTJOtKTdvGgNfwEnWY2CaEa14 3neA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dU/eUAUX7IkjZsgttuh1Gp6IYyyjhsKSGjoHIekrBvA=; b=UYj4mKTCu6nN3q4FGc+jpnDh9+dJ9AvL83pQujOTGaeqNTV+45Wk5vDy/8LZTXF2n+ WnjlcCQPayr90cAj0Q7je1EBY5ph04PijBiVnrfOo4++aZ1m2/Duq4ykhlJo+Q/m6FZL 2yjVTirDGWJumAoCHXPP/Nel7WvheNrunQx5AIdMacI4J2UbCJQYuSLWm/GqLdqLJoB+ VXiSvyJo1cI9OtqyOmIbljEmt21GXbx6ittgDpOLDeS+3iUvukK2PKjW8ZwNy8P4+bHj kQM4i0uaug26VqHuWv1iLw7P9SSc0M24eppVMLsvRp2YpYxYzpLVzV877mPA3q+er663 nS1w== X-Gm-Message-State: AA+aEWbrFUa+v+O8mVi3c4wESUrhCSsaDUDRcvfzQS5WyovT9qgEsKO+ Q24TNzuU2AgRhv1WuZTpwrk= X-Google-Smtp-Source: AFSGD/VE8Q/0UEil6tIKqP0WYh6e/SIvp65U1LF8YpECkLRTCHqDeJJmaQJ0C2/vj95v5SFZQqYweg== X-Received: by 2002:a17:902:724a:: with SMTP id c10mr27826816pll.51.1544078213098; Wed, 05 Dec 2018 22:36:53 -0800 (PST) Received: from yongji-Ubuntu.internal.baidu.com ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id x186sm26175249pfb.59.2018.12.05.22.36.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Dec 2018 22:36:52 -0800 (PST) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, marcandre.lureau@redhat.com Date: Thu, 6 Dec 2018 14:35:51 +0800 Message-Id: <20181206063552.6701-6-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181206063552.6701-1-xieyongji@baidu.com> References: <20181206063552.6701-1-xieyongji@baidu.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::641 Subject: [Qemu-devel] [PATCH for-4.0 5/6] vhost-user-blk: Add support for reconnecting backend 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: nixun@baidu.com, qemu-devel@nongnu.org, lilin24@baidu.com, zhangyu31@baidu.com, chaiwen@baidu.com, Xie Yongji Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Xie Yongji Since the new message VHOST_USER_SET_VRING_INFLIGHT, the backend is able to restart safely. This patch allow qemu to reconnect the backend after connection closed. Signed-off-by: Xie Yongji Signed-off-by: Ni Xun Signed-off-by: Zhang Yu --- hw/block/vhost-user-blk.c | 169 +++++++++++++++++++++++++++-- include/hw/virtio/vhost-user-blk.h | 4 + 2 files changed, 161 insertions(+), 12 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 1451940845..663e91bcf6 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -101,7 +101,7 @@ const VhostDevConfigOps blk_ops = { .vhost_dev_config_notifier = vhost_user_blk_handle_config_change, }; -static void vhost_user_blk_start(VirtIODevice *vdev) +static int vhost_user_blk_start(VirtIODevice *vdev) { VHostUserBlk *s = VHOST_USER_BLK(vdev); BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); @@ -110,13 +110,13 @@ static void vhost_user_blk_start(VirtIODevice *vdev) if (!k->set_guest_notifiers) { error_report("binding does not support guest notifiers"); - return; + return -ENOSYS; } ret = vhost_dev_enable_notifiers(&s->dev, vdev); if (ret < 0) { error_report("Error enabling host notifiers: %d", -ret); - return; + return ret; } ret = k->set_guest_notifiers(qbus->parent, s->dev.nvqs, true); @@ -140,12 +140,13 @@ static void vhost_user_blk_start(VirtIODevice *vdev) vhost_virtqueue_mask(&s->dev, vdev, i, false); } - return; + return ret; err_guest_notifiers: k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false); err_host_notifiers: vhost_dev_disable_notifiers(&s->dev, vdev); + return ret; } static void vhost_user_blk_stop(VirtIODevice *vdev) @@ -164,7 +165,6 @@ static void vhost_user_blk_stop(VirtIODevice *vdev) ret = k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false); if (ret < 0) { error_report("vhost guest notifier cleanup failed: %d", ret); - return; } vhost_dev_disable_notifiers(&s->dev, vdev); @@ -174,21 +174,39 @@ static void vhost_user_blk_set_status(VirtIODevice *vdev, uint8_t status) { VHostUserBlk *s = VHOST_USER_BLK(vdev); bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK; + int ret; if (!vdev->vm_running) { should_start = false; } - if (s->dev.started == should_start) { + if (s->should_start == should_start) { + return; + } + + if (!s->connected || s->dev.started == should_start) { + s->should_start = should_start; return; } if (should_start) { - vhost_user_blk_start(vdev); + s->should_start = true; + /* make sure we ignore fake guest kick by + * vhost_dev_enable_notifiers() */ + barrier(); + ret = vhost_user_blk_start(vdev); + if (ret < 0) { + error_report("vhost-user-blk: vhost start failed: %s", + strerror(-ret)); + qemu_chr_fe_disconnect(&s->chardev); + } } else { vhost_user_blk_stop(vdev); + /* make sure we ignore fake guest kick by + * vhost_dev_disable_notifiers() */ + barrier(); + s->should_start = false; } - } static uint64_t vhost_user_blk_get_features(VirtIODevice *vdev, @@ -218,13 +236,22 @@ static uint64_t vhost_user_blk_get_features(VirtIODevice *vdev, static void vhost_user_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) { VHostUserBlk *s = VHOST_USER_BLK(vdev); - int i; + int i, ret; if (!(virtio_host_has_feature(vdev, VIRTIO_F_VERSION_1) && !virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1))) { return; } + if (s->should_start) { + return; + } + s->should_start = true; + + if (!s->connected) { + return; + } + if (s->dev.started) { return; } @@ -232,7 +259,13 @@ static void vhost_user_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) /* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start * vhost here instead of waiting for .set_status(). */ - vhost_user_blk_start(vdev); + ret = vhost_user_blk_start(vdev); + if (ret < 0) { + error_report("vhost-user-blk: vhost start failed: %s", + strerror(-ret)); + qemu_chr_fe_disconnect(&s->chardev); + return; + } /* Kick right away to begin processing requests already in vring */ for (i = 0; i < s->dev.nvqs; i++) { @@ -245,6 +278,106 @@ static void vhost_user_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) } } +static void vhost_user_blk_reset(VirtIODevice *vdev) +{ + VHostUserBlk *s = VHOST_USER_BLK(vdev); + + if (s->vhost_user) { + vhost_user_inflight_reset(s->vhost_user); + } +} + +static int vhost_user_blk_connect(DeviceState *dev) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VHostUserBlk *s = VHOST_USER_BLK(vdev); + int ret = 0; + + if (s->connected) { + return 0; + } + s->connected = true; + + s->dev.nvqs = s->num_queues; + s->dev.vqs = s->vqs; + s->dev.vq_index = 0; + s->dev.backend_features = 0; + + vhost_dev_set_config_notifier(&s->dev, &blk_ops); + + ret = vhost_dev_init(&s->dev, s->vhost_user, VHOST_BACKEND_TYPE_USER, 0); + if (ret < 0) { + error_report("vhost-user-blk: vhost initialization failed: %s", + strerror(-ret)); + return ret; + } + + if (s->should_start && !s->dev.started) { + ret = vhost_user_blk_start(vdev); + if (ret < 0) { + error_report("vhost-user-blk: vhost start failed: %s", + strerror(-ret)); + return ret; + } + } + + return 0; +} + +static void vhost_user_blk_disconnect(DeviceState *dev) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VHostUserBlk *s = VHOST_USER_BLK(vdev); + + if (!s->connected) { + return; + } + s->connected = false; + + if (s->dev.started) { + vhost_user_blk_stop(vdev); + } + + vhost_dev_cleanup(&s->dev); +} + +static gboolean vhost_user_blk_watch(GIOChannel *chan, GIOCondition cond, + void *opaque) +{ + DeviceState *dev = opaque; + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VHostUserBlk *s = VHOST_USER_BLK(vdev); + + qemu_chr_fe_disconnect(&s->chardev); + + return true; +} + +static void vhost_user_blk_event(void *opaque, int event) +{ + DeviceState *dev = opaque; + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VHostUserBlk *s = VHOST_USER_BLK(vdev); + + switch (event) { + case CHR_EVENT_OPENED: + if (vhost_user_blk_connect(dev) < 0) { + qemu_chr_fe_disconnect(&s->chardev); + return; + } + s->watch = qemu_chr_fe_add_watch(&s->chardev, G_IO_HUP, + vhost_user_blk_watch, dev); + break; + case CHR_EVENT_CLOSED: + vhost_user_blk_disconnect(dev); + if (s->watch) { + g_source_remove(s->watch); + s->watch = 0; + } + break; + } +} + static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); @@ -284,8 +417,13 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) vhost_user_blk_handle_output); } + s->vqs = g_new(struct vhost_virtqueue, s->num_queues); + s->watch = 0; + s->should_start = false; + s->connected = true; + s->dev.nvqs = s->num_queues; - s->dev.vqs = g_new(struct vhost_virtqueue, s->dev.nvqs); + s->dev.vqs = s->vqs; s->dev.vq_index = 0; s->dev.backend_features = 0; @@ -309,6 +447,9 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) s->blkcfg.num_queues = s->num_queues; } + qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, vhost_user_blk_event, + NULL, (void *)dev, NULL, true); + return; vhost_err: @@ -328,8 +469,11 @@ static void vhost_user_blk_device_unrealize(DeviceState *dev, Error **errp) VHostUserBlk *s = VHOST_USER_BLK(dev); vhost_user_blk_set_status(vdev, 0); + qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, NULL, + NULL, NULL, NULL, false); vhost_dev_cleanup(&s->dev); - g_free(s->dev.vqs); + + g_free(s->vqs); virtio_cleanup(vdev); if (s->vhost_user) { @@ -379,6 +523,7 @@ static void vhost_user_blk_class_init(ObjectClass *klass, void *data) vdc->set_config = vhost_user_blk_set_config; vdc->get_features = vhost_user_blk_get_features; vdc->set_status = vhost_user_blk_set_status; + vdc->reset = vhost_user_blk_reset; } static const TypeInfo vhost_user_blk_info = { diff --git a/include/hw/virtio/vhost-user-blk.h b/include/hw/virtio/vhost-user-blk.h index d52944aeeb..560bb21459 100644 --- a/include/hw/virtio/vhost-user-blk.h +++ b/include/hw/virtio/vhost-user-blk.h @@ -37,6 +37,10 @@ typedef struct VHostUserBlk { uint32_t config_wce; struct vhost_dev dev; VhostUserState *vhost_user; + struct vhost_virtqueue *vqs; + guint watch; + bool should_start; + bool connected; } VHostUserBlk; #endif From patchwork Thu Dec 6 06:35:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 10715315 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B615C13AF for ; Thu, 6 Dec 2018 06:41:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A50EE2E357 for ; Thu, 6 Dec 2018 06:41:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 983F22E3DC; Thu, 6 Dec 2018 06:41:20 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 4DAE52E357 for ; Thu, 6 Dec 2018 06:41:20 +0000 (UTC) Received: from localhost ([::1]:39112 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUnLb-0005MM-He for patchwork-qemu-devel@patchwork.kernel.org; Thu, 06 Dec 2018 01:41:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52945) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUnHW-0001cT-Mo for qemu-devel@nongnu.org; Thu, 06 Dec 2018 01:37:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gUnHR-0003di-Iv for qemu-devel@nongnu.org; Thu, 06 Dec 2018 01:37:04 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:40888) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gUnHP-0003ZV-Sg for qemu-devel@nongnu.org; Thu, 06 Dec 2018 01:37:01 -0500 Received: by mail-pl1-x630.google.com with SMTP id u18so11311148plq.7 for ; Wed, 05 Dec 2018 22:36:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fo/iI2H+MPlzFNyjQ45gXFXk6RlXN6p3eD6WGRIUyeY=; b=X7IWaLpwtKfcvyYrMW83JAlyV9LqezQlM5RaS8FF6p/y+KXVAZfWYdbiZgRDsZhMsc KavA9uJlBCybgfi8H+S63uRBR4gvg7z6FumDxQCX/HS2a9GBmTLifZfmwQOmmjgVNGX5 dTJYDxiBd603o+y5nzG7D0zo4BkPvrue2BGpsiA/jrogQhm8Wg2de9OcIZg0oaKSWVKS 37WdOjpseRzUHOIIh//5J/Q1OEbNGKWgs1pdMO5K0jxSerTU1cuvZqJVroquMD18lGl5 zjwgb8qqHKFnqUXB4ehaZmxQ9ZMnFVrcwLlRPamWvigX0BlSViMSkWyBjTnXP7YyvnkG jHMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fo/iI2H+MPlzFNyjQ45gXFXk6RlXN6p3eD6WGRIUyeY=; b=i4VLzaK6TYz7ZCuc8kGsvmgNBmClQDHTBB9sMTrsOogl4QbfIvfZlWJPrrTci9i/51 4XsvW7dLBKpOgscAmooQ9GT3oB3oBxXosLkU8H7KE/mw+9nZlsBWGItJUxECKZi3Vdsk /8atA1MKcnnk2dau298DitEFPCuRZV8KWTC1Btw3ho+qPNsCpNmrJLLB1bs5xN14FrQc Gl4aQNmLK+eA/87j/cyf/UVz7Igr8s3UjcMAYvVgE2XdeEv+86M7biaEKhnA4VJiSLqB LhVa4HlGoLYXkxp1+A2ivXMFnoneOQn2RPtkMYwnLli90AoMt531/j2kk2UqQ0lrJbCS umsg== X-Gm-Message-State: AA+aEWYMzTKD+JI90wmdo8s1kGRzowXOMK9BfnxRV5QBn06AtqDQR7Om l1yOb6XmlB2Kg0A5vvquNxelChd69PA= X-Google-Smtp-Source: AFSGD/X5Fau1hyqHBamG6jPJ5FUhXfJMyGWs19nsKO5Hh6bZp5o1pDWuWPaAAyuOEz63smGvAPKM8A== X-Received: by 2002:a17:902:4c85:: with SMTP id b5mr25937391ple.226.1544078216605; Wed, 05 Dec 2018 22:36:56 -0800 (PST) Received: from yongji-Ubuntu.internal.baidu.com ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id x186sm26175249pfb.59.2018.12.05.22.36.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Dec 2018 22:36:56 -0800 (PST) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, marcandre.lureau@redhat.com Date: Thu, 6 Dec 2018 14:35:52 +0800 Message-Id: <20181206063552.6701-7-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181206063552.6701-1-xieyongji@baidu.com> References: <20181206063552.6701-1-xieyongji@baidu.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::630 Subject: [Qemu-devel] [PATCH for-4.0 6/6] contrib/vhost-user-blk: enable inflight I/O recording 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: nixun@baidu.com, qemu-devel@nongnu.org, lilin24@baidu.com, zhangyu31@baidu.com, chaiwen@baidu.com, Xie Yongji Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Xie Yongji This patch tells qemu that we now support inflight I/O recording so that qemu could offer shared memory to it. Signed-off-by: Xie Yongji Signed-off-by: Zhang Yu --- contrib/vhost-user-blk/vhost-user-blk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-blk/vhost-user-blk.c index 571f114a56..f87f9de8cd 100644 --- a/contrib/vhost-user-blk/vhost-user-blk.c +++ b/contrib/vhost-user-blk/vhost-user-blk.c @@ -328,7 +328,8 @@ vub_get_features(VuDev *dev) static uint64_t vub_get_protocol_features(VuDev *dev) { - return 1ull << VHOST_USER_PROTOCOL_F_CONFIG; + return 1ull << VHOST_USER_PROTOCOL_F_CONFIG | + 1uLL << VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD; } static int