From patchwork Thu Jan 3 10:18:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 10747177 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 2F9B814E5 for ; Thu, 3 Jan 2019 10:23:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D92728563 for ; Thu, 3 Jan 2019 10:23:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11A5B28623; Thu, 3 Jan 2019 10:23:27 +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 A560028563 for ; Thu, 3 Jan 2019 10:23:26 +0000 (UTC) Received: from localhost ([127.0.0.1]:50441 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gf09t-0000hf-Ta for patchwork-qemu-devel@patchwork.kernel.org; Thu, 03 Jan 2019 05:23:25 -0500 Received: from eggs.gnu.org ([208.118.235.92]:44182) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gf05z-0004Iq-Bs for qemu-devel@nongnu.org; Thu, 03 Jan 2019 05:19:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gf05x-0002uJ-DS for qemu-devel@nongnu.org; Thu, 03 Jan 2019 05:19:23 -0500 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:33839) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gf05v-0002sG-EE for qemu-devel@nongnu.org; Thu, 03 Jan 2019 05:19:20 -0500 Received: by mail-pf1-x444.google.com with SMTP id h3so16508060pfg.1 for ; Thu, 03 Jan 2019 02:19:17 -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=a7DLZuow3M9M2aEACsQREQCdzbl9zrjyaeO9vV3x0Ng=; b=XK5Ae/GZ8SSNhkn/irCZIyK6Kh+DkP+UgoG8+W+zqs9PWwlxPERgDEE+rR2/D9fo2V retT2V2wB/DF+2aNUje2zUBUPzedbBB64y27BIz0FR7vxZnB5a+LqcrOzfPC8ncjYMHz h4JCeR5T7ryTCmaUOp67jrMYaFHOv9zB65b1a7OzJOjXdeErXe2yCI89KoiGZsBLONfb E7n7V2hw4spKjcwKfaWb93aZ3EfXKKm/sc0W0vSAb7LLNvg9r5MVDEZIU2ovTJfJMnZy rtEE0AAuwCkupHFcSenMYH4bVwTKyOsGUSNrVCKq5IC06mpwOVgPNzuD6JTC13xsMvaZ H78g== 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=a7DLZuow3M9M2aEACsQREQCdzbl9zrjyaeO9vV3x0Ng=; b=gG+jGfeaE4i5tcEfwighq8CI6616nim0mA2W2YaXUa7DHM5/SzCgMYlouln23T/XrV j+HsbNpvVqvAaD+TrTOXqTjMKGKsGIHnRgHuBXTj+/h/zKHmYc9bCT42sj762UpM/5+R NBfF0jszv7WTJMHYGa5kd8w1k3gfXWanLj4ksdp3cmK/ep3M+bnl/wjDr222d045AK8X eXw6yJfl7vKgo7flprGW8V3kSEWUKg3myTouwLp2xJf3c/osMucCBRv10mvqYQpBHYsc sNUnhdx3MhATx/mN/JGIiXZOZg34sZMlNVn2IALHJjDiXonos9ICHUGcmrbEutbPP1pW YLIA== X-Gm-Message-State: AJcUukf4owsYnQncnjmgASsXBIP+YSNs42G8i5ZPxMkGC8LPYDRfG0zo koCZHEv+teKz+SbOZBBKTBU= X-Google-Smtp-Source: ALg8bN7bU530c85iQVYunKZjybV+maBoJXmx1HQKnRCXFyGFlHUoPdhOxXNUDeAaFN2RqxxnefltTA== X-Received: by 2002:a63:8742:: with SMTP id i63mr16333735pge.298.1546510757012; Thu, 03 Jan 2019 02:19:17 -0800 (PST) Received: from localhost ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id p7sm102550278pfj.72.2019.01.03.02.19.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Jan 2019 02:19:16 -0800 (PST) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, marcandre.lureau@redhat.com, berrange@redhat.com, jasowang@redhat.com, maxime.coquelin@redhat.com, yury-kotov@yandex-team.ru, wrfsh@yandex-team.ru Date: Thu, 3 Jan 2019 18:18:17 +0800 Message-Id: <20190103101819.7418-6-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190103101819.7418-1-xieyongji@baidu.com> References: <20190103101819.7418-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::444 Subject: [Qemu-devel] [PATCH v3 for-4.0 5/7] vhost-user-blk: Add support to provide shared memory to 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 This patch add supports for vhost-user-blk device to provide shared memory to backend. Signed-off-by: Xie Yongji Signed-off-by: Zhang Yu --- hw/block/vhost-user-blk.c | 26 ++++++++++++++++++++++++++ include/hw/virtio/vhost-user-blk.h | 1 + 2 files changed, 27 insertions(+) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 1451940845..27028cf996 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -126,6 +126,13 @@ static void vhost_user_blk_start(VirtIODevice *vdev) } s->dev.acked_features = vdev->guest_features; + + ret = vhost_dev_set_shm(&s->dev, s->shm); + if (ret < 0) { + error_report("Error set shared memory: %d", -ret); + goto err_guest_notifiers; + } + ret = vhost_dev_start(&s->dev, vdev); if (ret < 0) { error_report("Error starting vhost: %d", -ret); @@ -245,6 +252,13 @@ 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); + + vhost_dev_reset_shm(s->shm); +} + static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); @@ -284,6 +298,8 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) vhost_user_blk_handle_output); } + s->shm = g_new0(struct vhost_shm, 1); + s->dev.nvqs = s->num_queues; s->dev.vqs = g_new(struct vhost_virtqueue, s->dev.nvqs); s->dev.vq_index = 0; @@ -309,12 +325,19 @@ static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp) s->blkcfg.num_queues = s->num_queues; } + ret = vhost_dev_init_shm(&s->dev, s->shm); + if (ret < 0) { + error_setg(errp, "vhost-user-blk: init shared memory failed"); + goto vhost_err; + } + return; vhost_err: vhost_dev_cleanup(&s->dev); virtio_err: g_free(s->dev.vqs); + g_free(s->shm); virtio_cleanup(vdev); vhost_user_cleanup(user); @@ -329,7 +352,9 @@ static void vhost_user_blk_device_unrealize(DeviceState *dev, Error **errp) vhost_user_blk_set_status(vdev, 0); vhost_dev_cleanup(&s->dev); + vhost_dev_free_shm(s->shm); g_free(s->dev.vqs); + g_free(s->shm); virtio_cleanup(vdev); if (s->vhost_user) { @@ -379,6 +404,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..bb706d70b3 100644 --- a/include/hw/virtio/vhost-user-blk.h +++ b/include/hw/virtio/vhost-user-blk.h @@ -36,6 +36,7 @@ typedef struct VHostUserBlk { uint32_t queue_size; uint32_t config_wce; struct vhost_dev dev; + struct vhost_shm *shm; VhostUserState *vhost_user; } VHostUserBlk;