From nobody Thu May 2 02:28:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544463600918409.39633095600095; Mon, 10 Dec 2018 09:40:00 -0800 (PST) Received: from localhost ([::1]:33996 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWPXD-00057R-BW for importer@patchew.org; Mon, 10 Dec 2018 12:39:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46055) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWPPU-0006NB-2u for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWPPS-0003cU-5u for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:31:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:29013) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWPPS-0003cC-0K for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:31:58 -0500 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 mx1.redhat.com (Postfix) with ESMTPS id 6CEA888E50; Mon, 10 Dec 2018 17:31:56 +0000 (UTC) Received: from dgilbert-t530.redhat.com (unknown [10.36.118.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0FBDC1001F5E; Mon, 10 Dec 2018 17:31:53 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2018 17:31:45 +0000 Message-Id: <20181210173151.16629-2-dgilbert@redhat.com> In-Reply-To: <20181210173151.16629-1-dgilbert@redhat.com> References: <20181210173151.16629-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 10 Dec 2018 17:31:56 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH 1/7] virtio: Add shared memory capability 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: sweil@redhat.com, swhiteho@redhat.com, stefanha@redhat.com, vgoyal@redhat.com, miklos@szeredi.hu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Define a new capability type 'VIRTIO_PCI_CAP_SHARED_MEMORY_CFG' and the data structure 'virtio_pci_shm_cap' to go with it. They allow defining shared memory regions with sizes and offsets of 2^32 and more. Multiple instances of the capability are allowed and distinguished by a device-specific 'id'. Signed-off-by: Dr. David Alan Gilbert --- hw/virtio/virtio-pci.c | 20 ++++++++++++++++++++ include/standard-headers/linux/virtio_pci.h | 9 +++++++++ 2 files changed, 29 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index a954799267..1e737531b5 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1163,6 +1163,26 @@ static int virtio_pci_add_mem_cap(VirtIOPCIProxy *pr= oxy, return offset; } =20 +static int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy, + uint8_t bar, + uint64_t offset, uint64_t length, + uint8_t id) +{ + struct virtio_pci_shm_cap cap =3D { + .cap.cap_len =3D sizeof cap, + .cap.cfg_type =3D VIRTIO_PCI_CAP_SHARED_MEMORY_CFG, + }; + uint32_t mask32 =3D ~0; + + cap.cap.bar =3D bar; + cap.cap.length =3D cpu_to_le32(length & mask32); + cap.length_hi =3D cpu_to_le32((length >> 32) & mask32); + cap.cap.offset =3D cpu_to_le32(offset & mask32); + cap.offset_hi =3D cpu_to_le32((offset >> 32) & mask32); + cap.id =3D id; + return virtio_pci_add_mem_cap(proxy, &cap.cap); +} + static uint64_t virtio_pci_common_read(void *opaque, hwaddr addr, unsigned size) { diff --git a/include/standard-headers/linux/virtio_pci.h b/include/standard= -headers/linux/virtio_pci.h index 9262acd130..745d7a1942 100644 --- a/include/standard-headers/linux/virtio_pci.h +++ b/include/standard-headers/linux/virtio_pci.h @@ -113,6 +113,8 @@ #define VIRTIO_PCI_CAP_DEVICE_CFG 4 /* PCI configuration access */ #define VIRTIO_PCI_CAP_PCI_CFG 5 +/* Additional shared memory capability */ +#define VIRTIO_PCI_CAP_SHARED_MEMORY_CFG 8 =20 /* This is the PCI capability header: */ struct virtio_pci_cap { @@ -163,6 +165,13 @@ struct virtio_pci_cfg_cap { uint8_t pci_cfg_data[4]; /* Data for BAR access. */ }; =20 +struct virtio_pci_shm_cap { + struct virtio_pci_cap cap; + uint32_t offset_hi; /* Most sig 32 bits of offset */ + uint32_t length_hi; /* Most sig 32 bits of length */ + uint8_t id; /* To distinguish shm chunks */ +}; + /* Macro versions of offsets for the Old Timers! */ #define VIRTIO_PCI_CAP_VNDR 0 #define VIRTIO_PCI_CAP_NEXT 1 --=20 2.19.2 From nobody Thu May 2 02:28:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544463504585423.44497921347363; Mon, 10 Dec 2018 09:38:24 -0800 (PST) Received: from localhost ([::1]:33987 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWPVc-0003E2-Rj for importer@patchew.org; Mon, 10 Dec 2018 12:38:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46077) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWPPY-0006Qf-8k for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWPPW-0003dn-20 for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48746) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWPPU-0003ce-2k for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:01 -0500 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 mx1.redhat.com (Postfix) with ESMTPS id 5D44589AD5; Mon, 10 Dec 2018 17:31:58 +0000 (UTC) Received: from dgilbert-t530.redhat.com (unknown [10.36.118.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6ABE1001914; Mon, 10 Dec 2018 17:31:56 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2018 17:31:46 +0000 Message-Id: <20181210173151.16629-3-dgilbert@redhat.com> In-Reply-To: <20181210173151.16629-1-dgilbert@redhat.com> References: <20181210173151.16629-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 10 Dec 2018 17:31:58 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH 2/7] virtio: add vhost-user-fs-pci device 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: sweil@redhat.com, swhiteho@redhat.com, stefanha@redhat.com, vgoyal@redhat.com, miklos@szeredi.hu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi The virtio-fs virtio device provides shared file system access. The actual file server is implemented in an external vhost-user-fs device backend process. Launch QEMU like this: qemu -chardev socket,path=3D/tmp/vhost-fs.sock,id=3Dchr0 -device vhost-user-fs-pci,tag=3Dmyfs,chardev=3Dchr0 Signed-off-by: Stefan Hajnoczi --- configure | 10 + hw/virtio/Makefile.objs | 1 + hw/virtio/vhost-user-fs.c | 297 ++++++++++++++++++++ hw/virtio/virtio-pci.c | 52 ++++ hw/virtio/virtio-pci.h | 18 ++ include/hw/pci/pci.h | 1 + include/hw/virtio/vhost-user-fs.h | 45 +++ include/standard-headers/linux/virtio_fs.h | 41 +++ include/standard-headers/linux/virtio_ids.h | 1 + 9 files changed, 466 insertions(+) create mode 100644 hw/virtio/vhost-user-fs.c create mode 100644 include/hw/virtio/vhost-user-fs.h create mode 100644 include/standard-headers/linux/virtio_fs.h diff --git a/configure b/configure index 0a3c6a72c3..140b89d8f0 100755 --- a/configure +++ b/configure @@ -371,6 +371,7 @@ vhost_crypto=3D"no" vhost_scsi=3D"no" vhost_vsock=3D"no" vhost_user=3D"" +vhost_user_fs=3D"no" kvm=3D"no" hax=3D"no" hvf=3D"no" @@ -878,6 +879,7 @@ Linux) vhost_crypto=3D"yes" vhost_scsi=3D"yes" vhost_vsock=3D"yes" + vhost_user_fs=3D"yes" QEMU_INCLUDES=3D"-I\$(SRC_PATH)/linux-headers -I$PWD/linux-headers $QEMU= _INCLUDES" supported_os=3D"yes" libudev=3D"yes" @@ -1272,6 +1274,10 @@ for opt do ;; --enable-vhost-vsock) vhost_vsock=3D"yes" ;; + --disable-vhost-user-fs) vhost_user_fs=3D"no" + ;; + --enable-vhost-user-fs) vhost_user_fs=3D"yes" + ;; --disable-opengl) opengl=3D"no" ;; --enable-opengl) opengl=3D"yes" @@ -6054,6 +6060,7 @@ echo "vhost-crypto support $vhost_crypto" echo "vhost-scsi support $vhost_scsi" echo "vhost-vsock support $vhost_vsock" echo "vhost-user support $vhost_user" +echo "vhost-user-fs support $vhost_user_fs" echo "Trace backends $trace_backends" if have_backend "simple"; then echo "Trace output file $trace_file-" @@ -6524,6 +6531,9 @@ fi if test "$vhost_user" =3D "yes" ; then echo "CONFIG_VHOST_USER=3Dy" >> $config_host_mak fi +if test "$vhost_user_fs" =3D "yes" ; then + echo "CONFIG_VHOST_USER_FS=3Dy" >> $config_host_mak +fi if test "$blobs" =3D "yes" ; then echo "INSTALL_BLOBS=3Dyes" >> $config_host_mak fi diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index 1b2799cfd8..6783932231 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -11,6 +11,7 @@ obj-$(call land,$(CONFIG_VIRTIO_CRYPTO),$(CONFIG_VIRTIO_P= CI)) +=3D virtio-crypto-p =20 obj-$(CONFIG_LINUX) +=3D vhost.o vhost-backend.o vhost-user.o obj-$(CONFIG_VHOST_VSOCK) +=3D vhost-vsock.o +obj-$(CONFIG_VHOST_USER_FS) +=3D vhost-user-fs.o endif =20 common-obj-$(call lnot,$(call land,$(CONFIG_VIRTIO),$(CONFIG_LINUX))) +=3D= vhost-stub.o diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c new file mode 100644 index 0000000000..bc21beeac3 --- /dev/null +++ b/hw/virtio/vhost-user-fs.c @@ -0,0 +1,297 @@ +/* + * Vhost-user filesystem virtio device + * + * Copyright 2018 Red Hat, Inc. + * + * Authors: + * Stefan Hajnoczi + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * (at your option) any later version. See the COPYING file in the + * top-level directory. + */ + +#include "qemu/osdep.h" +#include +#include "standard-headers/linux/virtio_fs.h" +#include "qapi/error.h" +#include "hw/virtio/virtio-bus.h" +#include "hw/virtio/virtio-access.h" +#include "qemu/error-report.h" +#include "hw/virtio/vhost-user-fs.h" +#include "monitor/monitor.h" + +static void vuf_get_config(VirtIODevice *vdev, uint8_t *config) +{ + VHostUserFS *fs =3D VHOST_USER_FS(vdev); + struct virtio_fs_config fscfg =3D {}; + + /* strncpy(3) is okay, the field is not NUL-terminated at max size */ + strncpy((char *)fscfg.tag, fs->conf.tag, sizeof(fscfg.tag)); + + virtio_stl_p(vdev, &fscfg.num_queues, fs->conf.num_queues); + + memcpy(config, &fscfg, sizeof(fscfg)); +} + +static void vuf_start(VirtIODevice *vdev) +{ + VHostUserFS *fs =3D VHOST_USER_FS(vdev); + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + int ret; + int i; + + if (!k->set_guest_notifiers) { + error_report("binding does not support guest notifiers"); + return; + } + + ret =3D vhost_dev_enable_notifiers(&fs->vhost_dev, vdev); + if (ret < 0) { + error_report("Error enabling host notifiers: %d", -ret); + return; + } + + ret =3D k->set_guest_notifiers(qbus->parent, fs->vhost_dev.nvqs, true); + if (ret < 0) { + error_report("Error binding guest notifier: %d", -ret); + goto err_host_notifiers; + } + + fs->vhost_dev.acked_features =3D vdev->guest_features; + ret =3D vhost_dev_start(&fs->vhost_dev, vdev); + if (ret < 0) { + error_report("Error starting vhost: %d", -ret); + goto err_guest_notifiers; + } + + /* guest_notifier_mask/pending not used yet, so just unmask + * everything here. virtio-pci will do the right thing by + * enabling/disabling irqfd. + */ + for (i =3D 0; i < fs->vhost_dev.nvqs; i++) { + vhost_virtqueue_mask(&fs->vhost_dev, vdev, i, false); + } + + return; + +err_guest_notifiers: + k->set_guest_notifiers(qbus->parent, fs->vhost_dev.nvqs, false); +err_host_notifiers: + vhost_dev_disable_notifiers(&fs->vhost_dev, vdev); +} + +static void vuf_stop(VirtIODevice *vdev) +{ + VHostUserFS *fs =3D VHOST_USER_FS(vdev); + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + int ret; + + if (!k->set_guest_notifiers) { + return; + } + + vhost_dev_stop(&fs->vhost_dev, vdev); + + ret =3D k->set_guest_notifiers(qbus->parent, fs->vhost_dev.nvqs, false= ); + if (ret < 0) { + error_report("vhost guest notifier cleanup failed: %d", ret); + return; + } + + vhost_dev_disable_notifiers(&fs->vhost_dev, vdev); +} + +static void vuf_set_status(VirtIODevice *vdev, uint8_t status) +{ + VHostUserFS *fs =3D VHOST_USER_FS(vdev); + bool should_start =3D status & VIRTIO_CONFIG_S_DRIVER_OK; + + if (!vdev->vm_running) { + should_start =3D false; + } + + if (fs->vhost_dev.started =3D=3D should_start) { + return; + } + + if (should_start) { + vuf_start(vdev); + } else { + vuf_stop(vdev); + } +} + +static uint64_t vuf_get_features(VirtIODevice *vdev, + uint64_t requested_features, + Error **errp) +{ + /* No feature bits used yet */ + return requested_features; +} + +static void vuf_handle_output(VirtIODevice *vdev, VirtQueue *vq) +{ + /* Do nothing */ +} + +static void vuf_guest_notifier_mask(VirtIODevice *vdev, int idx, + bool mask) +{ + VHostUserFS *fs =3D VHOST_USER_FS(vdev); + + vhost_virtqueue_mask(&fs->vhost_dev, vdev, idx, mask); +} + +static bool vuf_guest_notifier_pending(VirtIODevice *vdev, int idx) +{ + VHostUserFS *fs =3D VHOST_USER_FS(vdev); + + return vhost_virtqueue_pending(&fs->vhost_dev, idx); +} + +static void vuf_device_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserFS *fs =3D VHOST_USER_FS(dev); + unsigned int i; + size_t len; + int ret; + + if (!fs->conf.chardev.chr) { + error_setg(errp, "missing chardev"); + return; + } + + if (!fs->conf.tag) { + error_setg(errp, "missing tag property"); + return; + } + len =3D strlen(fs->conf.tag); + if (len =3D=3D 0) { + error_setg(errp, "tag property cannot be empty"); + return; + } + if (len > sizeof_field(struct virtio_fs_config, tag)) { + error_setg(errp, "tag property must be %zu bytes or less", + sizeof_field(struct virtio_fs_config, tag)); + return; + } + + if (fs->conf.num_queues =3D=3D 0) { + error_setg(errp, "num-queues property must be larger than 0"); + return; + } + + if (!is_power_of_2(fs->conf.queue_size)) { + error_setg(errp, "queue-size property must be a power of 2"); + return; + } + + if (fs->conf.queue_size > VIRTQUEUE_MAX_SIZE) { + error_setg(errp, "queue-size property must be %u or smaller", + VIRTQUEUE_MAX_SIZE); + return; + } + + fs->vhost_user =3D vhost_user_init(); + if (!fs->vhost_user) { + error_setg(errp, "failed to initialize vhost-user"); + return; + } + fs->vhost_user->chr =3D &fs->conf.chardev; + + virtio_init(vdev, "vhost-user-fs", VIRTIO_ID_FS, + sizeof(struct virtio_fs_config)); + + /* Notifications queue */ + virtio_add_queue(vdev, fs->conf.queue_size, vuf_handle_output); + + /* Hiprio queue */ + virtio_add_queue(vdev, fs->conf.queue_size, vuf_handle_output); + + /* Request queues */ + for (i =3D 0; i < fs->conf.num_queues; i++) { + virtio_add_queue(vdev, fs->conf.queue_size, vuf_handle_output); + } + + fs->vhost_dev.nvqs =3D 2 + fs->conf.num_queues; + fs->vhost_dev.vqs =3D g_new0(struct vhost_virtqueue, fs->vhost_dev.nvq= s); + ret =3D vhost_dev_init(&fs->vhost_dev, fs->vhost_user, + VHOST_BACKEND_TYPE_USER, 0); + if (ret < 0) { + error_setg_errno(errp, -ret, "vhost_dev_init failed"); + goto err_virtio; + } + + return; + +err_virtio: + vhost_user_cleanup(fs->vhost_user); + g_free(fs->vhost_user); + virtio_cleanup(vdev); + g_free(fs->vhost_dev.vqs); + return; +} + +static void vuf_device_unrealize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserFS *fs =3D VHOST_USER_FS(dev); + + /* This will stop vhost backend if appropriate. */ + vuf_set_status(vdev, 0); + + vhost_dev_cleanup(&fs->vhost_dev); + + if (fs->vhost_user) { + vhost_user_cleanup(fs->vhost_user); + g_free(fs->vhost_user); + fs->vhost_user =3D NULL; + } + + virtio_cleanup(vdev); + g_free(fs->vhost_dev.vqs); + fs->vhost_dev.vqs =3D NULL; +} + +static Property vuf_properties[] =3D { + DEFINE_PROP_CHR("chardev", VHostUserFS, conf.chardev), + DEFINE_PROP_STRING("tag", VHostUserFS, conf.tag), + DEFINE_PROP_UINT16("num-queues", VHostUserFS, conf.num_queues, 1), + DEFINE_PROP_UINT16("queue-size", VHostUserFS, conf.queue_size, 128), + DEFINE_PROP_STRING("vhostfd", VHostUserFS, conf.vhostfd), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vuf_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); + + dc->props =3D vuf_properties; + set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); + vdc->realize =3D vuf_device_realize; + vdc->unrealize =3D vuf_device_unrealize; + vdc->get_features =3D vuf_get_features; + vdc->get_config =3D vuf_get_config; + vdc->set_status =3D vuf_set_status; + vdc->guest_notifier_mask =3D vuf_guest_notifier_mask; + vdc->guest_notifier_pending =3D vuf_guest_notifier_pending; +} + +static const TypeInfo vuf_info =3D { + .name =3D TYPE_VHOST_USER_FS, + .parent =3D TYPE_VIRTIO_DEVICE, + .instance_size =3D sizeof(VHostUserFS), + .class_init =3D vuf_class_init, +}; + +static void vuf_register_types(void) +{ + type_register_static(&vuf_info); +} + +type_init(vuf_register_types) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 1e737531b5..d744f93655 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -2665,6 +2665,55 @@ static const TypeInfo virtio_host_pci_info =3D { }; #endif =20 +/* vhost-user-fs-pci */ + +#ifdef CONFIG_VHOST_USER_FS +static Property vhost_user_fs_pci_properties[] =3D { + /* TODO multiqueue */ + DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 4), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vhost_user_fs_pci_realize(VirtIOPCIProxy *vpci_dev, Error **er= rp) +{ + VHostUserFSPCI *dev =3D VHOST_USER_FS_PCI(vpci_dev); + DeviceState *vdev =3D DEVICE(&dev->vdev); + + qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); + object_property_set_bool(OBJECT(vdev), true, "realized", errp); +} + +static void vhost_user_fs_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioPCIClass *k =3D VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k =3D PCI_DEVICE_CLASS(klass); + k->realize =3D vhost_user_fs_pci_realize; + set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); + dc->props =3D vhost_user_fs_pci_properties; + pcidev_k->vendor_id =3D PCI_VENDOR_ID_REDHAT_QUMRANET; + pcidev_k->device_id =3D PCI_DEVICE_ID_VIRTIO_FS; + pcidev_k->revision =3D 0x00; + pcidev_k->class_id =3D PCI_CLASS_STORAGE_OTHER; +} + +static void vhost_user_fs_pci_instance_init(Object *obj) +{ + VHostUserFSPCI *dev =3D VHOST_USER_FS_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VHOST_USER_FS); +} + +static const TypeInfo vhost_user_fs_pci_info =3D { + .name =3D TYPE_VHOST_USER_FS_PCI, + .parent =3D TYPE_VIRTIO_PCI, + .instance_size =3D sizeof(VHostUserFSPCI), + .instance_init =3D vhost_user_fs_pci_instance_init, + .class_init =3D vhost_user_fs_pci_class_init, +}; +#endif + /* virtio-pci-bus */ =20 static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size, @@ -2743,6 +2792,9 @@ static void virtio_pci_register_types(void) #ifdef CONFIG_VHOST_VSOCK type_register_static(&vhost_vsock_pci_info); #endif +#ifdef CONFIG_VHOST_USER_FS + type_register_static(&vhost_user_fs_pci_info); +#endif } =20 type_init(virtio_pci_register_types) diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h index 813082b0d7..a635dc564c 100644 --- a/hw/virtio/virtio-pci.h +++ b/hw/virtio/virtio-pci.h @@ -40,6 +40,9 @@ #ifdef CONFIG_VHOST_VSOCK #include "hw/virtio/vhost-vsock.h" #endif +#ifdef CONFIG_VHOST_USER_FS +#include "hw/virtio/vhost-user-fs.h" +#endif =20 typedef struct VirtIOPCIProxy VirtIOPCIProxy; typedef struct VirtIOBlkPCI VirtIOBlkPCI; @@ -57,6 +60,7 @@ typedef struct VirtIOInputHostPCI VirtIOInputHostPCI; typedef struct VirtIOGPUPCI VirtIOGPUPCI; typedef struct VHostVSockPCI VHostVSockPCI; typedef struct VirtIOCryptoPCI VirtIOCryptoPCI; +typedef struct VHostUserFSPCI VHostUserFSPCI; =20 /* virtio-pci-bus */ =20 @@ -414,6 +418,20 @@ struct VirtIOCryptoPCI { VirtIOCrypto vdev; }; =20 +#ifdef CONFIG_VHOST_USER_FS +/* + * vhost-user-fs-pci: This extends VirtioPCIProxy. + */ +#define TYPE_VHOST_USER_FS_PCI "vhost-user-fs-pci" +#define VHOST_USER_FS_PCI(obj) \ + OBJECT_CHECK(VHostUserFSPCI, (obj), TYPE_VHOST_USER_FS_PCI) + +struct VHostUserFSPCI { + VirtIOPCIProxy parent_obj; + VHostUserFS vdev; +}; +#endif + /* Virtio ABI version, if we increment this, we break the guest driver. */ #define VIRTIO_PCI_ABI_VERSION 0 =20 diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index e6514bba23..2adc3bf45f 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -85,6 +85,7 @@ extern bool pci_available; #define PCI_DEVICE_ID_VIRTIO_RNG 0x1005 #define PCI_DEVICE_ID_VIRTIO_9P 0x1009 #define PCI_DEVICE_ID_VIRTIO_VSOCK 0x1012 +#define PCI_DEVICE_ID_VIRTIO_FS 0x1019 =20 #define PCI_VENDOR_ID_REDHAT 0x1b36 #define PCI_DEVICE_ID_REDHAT_BRIDGE 0x0001 diff --git a/include/hw/virtio/vhost-user-fs.h b/include/hw/virtio/vhost-us= er-fs.h new file mode 100644 index 0000000000..29629acc54 --- /dev/null +++ b/include/hw/virtio/vhost-user-fs.h @@ -0,0 +1,45 @@ +/* + * Vhost-user filesystem virtio device + * + * Copyright 2018 Red Hat, Inc. + * + * Authors: + * Stefan Hajnoczi + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * (at your option) any later version. See the COPYING file in the + * top-level directory. + */ + +#ifndef _QEMU_VHOST_USER_FS_H +#define _QEMU_VHOST_USER_FS_H + +#include "hw/virtio/virtio.h" +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-user.h" +#include "chardev/char-fe.h" + +#define TYPE_VHOST_USER_FS "vhost-user-fs-device" +#define VHOST_USER_FS(obj) \ + OBJECT_CHECK(VHostUserFS, (obj), TYPE_VHOST_USER_FS) + +typedef struct { + CharBackend chardev; + char *tag; + uint16_t num_queues; + uint16_t queue_size; + char *vhostfd; +} VHostUserFSConf; + +typedef struct { + /*< private >*/ + VirtIODevice parent; + VHostUserFSConf conf; + struct vhost_virtqueue *vhost_vqs; + struct vhost_dev vhost_dev; + VhostUserState *vhost_user; + + /*< public >*/ +} VHostUserFS; + +#endif /* _QEMU_VHOST_USER_FS_H */ diff --git a/include/standard-headers/linux/virtio_fs.h b/include/standard-= headers/linux/virtio_fs.h new file mode 100644 index 0000000000..4f811a0b70 --- /dev/null +++ b/include/standard-headers/linux/virtio_fs.h @@ -0,0 +1,41 @@ +#ifndef _LINUX_VIRTIO_FS_H +#define _LINUX_VIRTIO_FS_H +/* This header is BSD licensed so anyone can use the definitions to implem= ent + * compatible drivers/servers. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of IBM nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``A= S IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP= OSE + * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT= IAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STR= ICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W= AY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. */ +#include "standard-headers/linux/types.h" +#include "standard-headers/linux/virtio_ids.h" +#include "standard-headers/linux/virtio_config.h" +#include "standard-headers/linux/virtio_types.h" + +struct virtio_fs_config { + /* Filesystem name (UTF-8, not NUL-terminated, padded with NULs) */ + uint8_t tag[36]; + + /* Number of request queues */ + uint32_t num_queues; +} QEMU_PACKED; + +#endif /* _LINUX_VIRTIO_FS_H */ diff --git a/include/standard-headers/linux/virtio_ids.h b/include/standard= -headers/linux/virtio_ids.h index 6d5c3b2d4f..884b0e2734 100644 --- a/include/standard-headers/linux/virtio_ids.h +++ b/include/standard-headers/linux/virtio_ids.h @@ -43,5 +43,6 @@ #define VIRTIO_ID_INPUT 18 /* virtio input */ #define VIRTIO_ID_VSOCK 19 /* virtio vsock transport */ #define VIRTIO_ID_CRYPTO 20 /* virtio crypto */ +#define VIRTIO_ID_FS 26 /* virtio filesystem */ =20 #endif /* _LINUX_VIRTIO_IDS_H */ --=20 2.19.2 From nobody Thu May 2 02:28:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544463258658113.69458054455379; Mon, 10 Dec 2018 09:34:18 -0800 (PST) Received: from localhost ([::1]:33964 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWPRh-0007gZ-0L for importer@patchew.org; Mon, 10 Dec 2018 12:34:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46081) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWPPY-0006Qt-IA for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWPPX-0003e7-Ab for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52984) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWPPV-0003dG-W7 for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:02 -0500 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 mx1.redhat.com (Postfix) with ESMTPS id E99172D7EF; Mon, 10 Dec 2018 17:31:59 +0000 (UTC) Received: from dgilbert-t530.redhat.com (unknown [10.36.118.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E8AB1001F5E; Mon, 10 Dec 2018 17:31:58 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2018 17:31:47 +0000 Message-Id: <20181210173151.16629-4-dgilbert@redhat.com> In-Reply-To: <20181210173151.16629-1-dgilbert@redhat.com> References: <20181210173151.16629-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 10 Dec 2018 17:31:59 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH 3/7] virtio-fs: Add cache BAR 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: sweil@redhat.com, swhiteho@redhat.com, stefanha@redhat.com, vgoyal@redhat.com, miklos@szeredi.hu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Add a cache BAR into which files will be directly mapped. The size cacn be set with the cache-size=3D property, e.g. -device vhost-user-fs-pci,chardev=3Dchar0,tag=3Dmyfs,cache-size=3D16G Signed-off-by: Dr. David Alan Gilbert --- hw/virtio/vhost-user-fs.c | 16 ++++++++++++++++ hw/virtio/virtio-pci.c | 19 +++++++++++++++++++ hw/virtio/virtio-pci.h | 1 + include/hw/virtio/vhost-user-fs.h | 2 ++ include/standard-headers/linux/virtio_fs.h | 5 +++++ 5 files changed, 43 insertions(+) diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index bc21beeac3..14ee922661 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -195,6 +195,21 @@ static void vuf_device_realize(DeviceState *dev, Error= **errp) VIRTQUEUE_MAX_SIZE); return; } + if (!is_power_of_2(fs->conf.cache_size) || + fs->conf.cache_size < sysconf(_SC_PAGESIZE)) { + error_setg(errp, "cache-size property must be a power of 2 " + "no smaller than the page size"); + return; + } + /* We need a region with some host memory, 'ram' is the easiest */ + memory_region_init_ram_nomigrate(&fs->cache, OBJECT(vdev), + "virtio-fs-cache", + fs->conf.cache_size, NULL); + /* But we don't actually want anyone reading/writing the raw + * area with no cache data. + */ + mprotect(memory_region_get_ram_ptr(&fs->cache), fs->conf.cache_size, + PROT_NONE); =20 fs->vhost_user =3D vhost_user_init(); if (!fs->vhost_user) { @@ -263,6 +278,7 @@ static Property vuf_properties[] =3D { DEFINE_PROP_UINT16("num-queues", VHostUserFS, conf.num_queues, 1), DEFINE_PROP_UINT16("queue-size", VHostUserFS, conf.queue_size, 128), DEFINE_PROP_STRING("vhostfd", VHostUserFS, conf.vhostfd), + DEFINE_PROP_SIZE("cache-size", VHostUserFS, conf.cache_size, 1ull << 3= 0), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index d744f93655..e819a29fb1 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -18,6 +18,7 @@ #include "qemu/osdep.h" =20 #include "standard-headers/linux/virtio_pci.h" +#include "standard-headers/linux/virtio_fs.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-blk.h" #include "hw/virtio/virtio-net.h" @@ -2678,9 +2679,27 @@ static void vhost_user_fs_pci_realize(VirtIOPCIProxy= *vpci_dev, Error **errp) { VHostUserFSPCI *dev =3D VHOST_USER_FS_PCI(vpci_dev); DeviceState *vdev =3D DEVICE(&dev->vdev); + uint64_t cachesize; =20 qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); object_property_set_bool(OBJECT(vdev), true, "realized", errp); + cachesize =3D memory_region_size(&dev->vdev.cache); + + /* The bar starts with the data/DAX cache + * Others will be added later. + */ + memory_region_init(&dev->cachebar, OBJECT(vpci_dev), + "vhost-fs-pci-cachebar", cachesize); + memory_region_add_subregion(&dev->cachebar, 0, &dev->vdev.cache); + virtio_pci_add_shm_cap(vpci_dev, VIRTIO_FS_PCI_CACHE_BAR, 0, cachesize, + VIRTIO_FS_PCI_SHMCAP_ID_CACHE); + + /* After 'realized' so the memory region exists */ + pci_register_bar(&vpci_dev->pci_dev, VIRTIO_FS_PCI_CACHE_BAR, + PCI_BASE_ADDRESS_SPACE_MEMORY | + PCI_BASE_ADDRESS_MEM_PREFETCH | + PCI_BASE_ADDRESS_MEM_TYPE_64, + &dev->cachebar); } =20 static void vhost_user_fs_pci_class_init(ObjectClass *klass, void *data) diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h index a635dc564c..53b87f245c 100644 --- a/hw/virtio/virtio-pci.h +++ b/hw/virtio/virtio-pci.h @@ -429,6 +429,7 @@ struct VirtIOCryptoPCI { struct VHostUserFSPCI { VirtIOPCIProxy parent_obj; VHostUserFS vdev; + MemoryRegion cachebar; }; #endif =20 diff --git a/include/hw/virtio/vhost-user-fs.h b/include/hw/virtio/vhost-us= er-fs.h index 29629acc54..be153e1c7a 100644 --- a/include/hw/virtio/vhost-user-fs.h +++ b/include/hw/virtio/vhost-user-fs.h @@ -29,6 +29,7 @@ typedef struct { uint16_t num_queues; uint16_t queue_size; char *vhostfd; + size_t cache_size; } VHostUserFSConf; =20 typedef struct { @@ -40,6 +41,7 @@ typedef struct { VhostUserState *vhost_user; =20 /*< public >*/ + MemoryRegion cache; } VHostUserFS; =20 #endif /* _QEMU_VHOST_USER_FS_H */ diff --git a/include/standard-headers/linux/virtio_fs.h b/include/standard-= headers/linux/virtio_fs.h index 4f811a0b70..b5f137ca79 100644 --- a/include/standard-headers/linux/virtio_fs.h +++ b/include/standard-headers/linux/virtio_fs.h @@ -38,4 +38,9 @@ struct virtio_fs_config { uint32_t num_queues; } QEMU_PACKED; =20 +#define VIRTIO_FS_PCI_CACHE_BAR 2 + +/* For the id field in virtio_pci_shm_cap */ +#define VIRTIO_FS_PCI_SHMCAP_ID_CACHE 0 + #endif /* _LINUX_VIRTIO_FS_H */ --=20 2.19.2 From nobody Thu May 2 02:28:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544463757588388.40708946502536; Mon, 10 Dec 2018 09:42:37 -0800 (PST) Received: from localhost ([::1]:34014 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWPZf-0007CE-WC for importer@patchew.org; Mon, 10 Dec 2018 12:42:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46089) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWPPZ-0006RJ-0p for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWPPX-0003eS-Ix for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:26824) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWPPX-0003dh-9f for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:03 -0500 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 mx1.redhat.com (Postfix) with ESMTPS id 9336230224BE; Mon, 10 Dec 2018 17:32:01 +0000 (UTC) Received: from dgilbert-t530.redhat.com (unknown [10.36.118.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39B341001914; Mon, 10 Dec 2018 17:32:00 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2018 17:31:48 +0000 Message-Id: <20181210173151.16629-5-dgilbert@redhat.com> In-Reply-To: <20181210173151.16629-1-dgilbert@redhat.com> References: <20181210173151.16629-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 10 Dec 2018 17:32:01 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH 4/7] virtio-fs: Add vhost-user slave commands for mapping 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: sweil@redhat.com, swhiteho@redhat.com, stefanha@redhat.com, vgoyal@redhat.com, miklos@szeredi.hu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" The daemon may request that fd's be mapped into the virtio-fs cache visible to the guest. These mappings are triggered by commands sent over the slave fd from the daemon. Signed-off-by: Dr. David Alan Gilbert --- contrib/libvhost-user/libvhost-user.h | 3 +++ docs/interop/vhost-user.txt | 35 +++++++++++++++++++++++++++ hw/virtio/vhost-user-fs.c | 20 +++++++++++++++ hw/virtio/vhost-user.c | 16 ++++++++++++ include/hw/virtio/vhost-user-fs.h | 24 ++++++++++++++++++ 5 files changed, 98 insertions(+) diff --git a/contrib/libvhost-user/libvhost-user.h b/contrib/libvhost-user/= libvhost-user.h index 4aa55b4d2d..6cff0ff189 100644 --- a/contrib/libvhost-user/libvhost-user.h +++ b/contrib/libvhost-user/libvhost-user.h @@ -99,6 +99,9 @@ typedef enum VhostUserSlaveRequest { VHOST_USER_SLAVE_IOTLB_MSG =3D 1, VHOST_USER_SLAVE_CONFIG_CHANGE_MSG =3D 2, VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG =3D 3, + VHOST_USER_SLAVE_FS_MAP =3D 4, + VHOST_USER_SLAVE_FS_UNMAP =3D 5, + VHOST_USER_SLAVE_FS_SYNC =3D 6, VHOST_USER_SLAVE_MAX } VhostUserSlaveRequest; =20 diff --git a/docs/interop/vhost-user.txt b/docs/interop/vhost-user.txt index c2194711d9..29cdd74523 100644 --- a/docs/interop/vhost-user.txt +++ b/docs/interop/vhost-user.txt @@ -815,6 +815,41 @@ Slave message types This request should be sent only when VHOST_USER_PROTOCOL_F_HOST_NOT= IFIER protocol feature has been successfully negotiated. =20 + * VHOST_USER_SLAVE_FS_MAP + + Id: 4 + Equivalent ioctl: N/A + Slave payload: fd + n * (offset + address + len) + Master payload: N/A + + Requests that the QEMU mmap the given fd into the virtio-fs cache; + multiple chunks can be mapped in one command. + A reply is generated indicating whether mapping succeeded. + + * VHOST_USER_SLAVE_FS_UNMAP + + Id: 5 + Equivalent ioctl: N/A + Slave payload: n * (address + len) + Master payload: N/A + + Requests that the QEMU un-mmap the given range in the virtio-fs cach= e; + multiple chunks can be unmapped in one command. + A reply is generated indicating whether unmapping succeeded. + + * VHOST_USER_SLAVE_FS_SYNC + + Id: 6 + Equivalent ioctl: N/A + Slave payload: n * (address + len) + Master payload: N/A + + Requests that the QEMU causes any changes to the virtio-fs cache to + be synchronised with the backing files. Multiple chunks can be sync= ed + in one command. + A reply is generated indicating whether syncing succeeded. + [Semantic details TBD] + VHOST_USER_PROTOCOL_F_REPLY_ACK: ------------------------------- The original vhost-user specification only demands replies for certain diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index 14ee922661..da70d9cd2c 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -21,6 +21,26 @@ #include "hw/virtio/vhost-user-fs.h" #include "monitor/monitor.h" =20 +int vhost_user_fs_slave_map(struct vhost_dev *dev, VhostUserFSSlaveMsg *sm, + int fd) +{ + /* TODO */ + return -1; +} + +int vhost_user_fs_slave_unmap(struct vhost_dev *dev, VhostUserFSSlaveMsg *= sm) +{ + /* TODO */ + return -1; +} + +int vhost_user_fs_slave_sync(struct vhost_dev *dev, VhostUserFSSlaveMsg *s= m) +{ + /* TODO */ + return -1; +} + + static void vuf_get_config(VirtIODevice *vdev, uint8_t *config) { VHostUserFS *fs =3D VHOST_USER_FS(vdev); diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index e09bed0e4a..beb028c7e2 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -12,6 +12,7 @@ #include "qapi/error.h" #include "hw/virtio/vhost.h" #include "hw/virtio/vhost-user.h" +#include "hw/virtio/vhost-user-fs.h" #include "hw/virtio/vhost-backend.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-net.h" @@ -97,6 +98,9 @@ typedef enum VhostUserSlaveRequest { VHOST_USER_SLAVE_IOTLB_MSG =3D 1, VHOST_USER_SLAVE_CONFIG_CHANGE_MSG =3D 2, VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG =3D 3, + VHOST_USER_SLAVE_FS_MAP =3D 4, + VHOST_USER_SLAVE_FS_UNMAP =3D 5, + VHOST_USER_SLAVE_FS_SYNC =3D 6, VHOST_USER_SLAVE_MAX } VhostUserSlaveRequest; =20 @@ -169,6 +173,7 @@ typedef union { VhostUserConfig config; VhostUserCryptoSession session; VhostUserVringArea area; + VhostUserFSSlaveMsg fs; } VhostUserPayload; =20 typedef struct VhostUserMsg { @@ -1010,6 +1015,17 @@ static void slave_read(void *opaque) ret =3D vhost_user_slave_handle_vring_host_notifier(dev, &payload.= area, fd[0]); break; +#ifdef CONFIG_VHOST_USER_FS + case VHOST_USER_SLAVE_FS_MAP: + ret =3D vhost_user_fs_slave_map(dev, &payload.fs, fd[0]); + break; + case VHOST_USER_SLAVE_FS_UNMAP: + ret =3D vhost_user_fs_slave_unmap(dev, &payload.fs); + break; + case VHOST_USER_SLAVE_FS_SYNC: + ret =3D vhost_user_fs_slave_sync(dev, &payload.fs); + break; +#endif default: error_report("Received unexpected msg type."); ret =3D -EINVAL; diff --git a/include/hw/virtio/vhost-user-fs.h b/include/hw/virtio/vhost-us= er-fs.h index be153e1c7a..9989bcd9e7 100644 --- a/include/hw/virtio/vhost-user-fs.h +++ b/include/hw/virtio/vhost-user-fs.h @@ -23,6 +23,24 @@ #define VHOST_USER_FS(obj) \ OBJECT_CHECK(VHostUserFS, (obj), TYPE_VHOST_USER_FS) =20 +/* Structures carried over the slave channel back to QEMU */ +#define VHOST_USER_FS_SLAVE_ENTRIES 8 + +/* For the flags field of VhostUserFSSlaveMsg */ +#define VHOST_USER_FS_FLAG_MAP_R (1ull << 0) +#define VHOST_USER_FS_FLAG_MAP_W (1ull << 1) + +typedef struct { + /* Offsets within the file being mapped */ + uint64_t fd_offset[VHOST_USER_FS_SLAVE_ENTRIES]; + /* Offsets within the cache */ + uint64_t c_offset[VHOST_USER_FS_SLAVE_ENTRIES]; + /* Lengths of sections */ + uint64_t len[VHOST_USER_FS_SLAVE_ENTRIES]; + /* Flags, from VHOST_USER_FS_FLAG_* */ + uint64_t flags[VHOST_USER_FS_SLAVE_ENTRIES]; +} VhostUserFSSlaveMsg; + typedef struct { CharBackend chardev; char *tag; @@ -44,4 +62,10 @@ typedef struct { MemoryRegion cache; } VHostUserFS; =20 +/* Callbacks from the vhost-user code for slave commands */ +int vhost_user_fs_slave_map(struct vhost_dev *dev, VhostUserFSSlaveMsg *sm, + int fd); +int vhost_user_fs_slave_unmap(struct vhost_dev *dev, VhostUserFSSlaveMsg *= sm); +int vhost_user_fs_slave_sync(struct vhost_dev *dev, VhostUserFSSlaveMsg *s= m); + #endif /* _QEMU_VHOST_USER_FS_H */ --=20 2.19.2 From nobody Thu May 2 02:28:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 154446400800995.39689995607785; Mon, 10 Dec 2018 09:46:48 -0800 (PST) Received: from localhost ([::1]:34047 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWPdm-00024E-Oq for importer@patchew.org; Mon, 10 Dec 2018 12:46:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46114) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWPPb-0006TQ-GJ for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWPPY-0003ek-9F for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52586) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWPPX-0003eM-Ur for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:04 -0500 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 mx1.redhat.com (Postfix) with ESMTPS id 3F8C130016F4; Mon, 10 Dec 2018 17:32:03 +0000 (UTC) Received: from dgilbert-t530.redhat.com (unknown [10.36.118.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7EFA1001914; Mon, 10 Dec 2018 17:32:01 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2018 17:31:49 +0000 Message-Id: <20181210173151.16629-6-dgilbert@redhat.com> In-Reply-To: <20181210173151.16629-1-dgilbert@redhat.com> References: <20181210173151.16629-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 10 Dec 2018 17:32:03 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH 5/7] virtio-fs: Fill in slave commands for mapping 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: sweil@redhat.com, swhiteho@redhat.com, stefanha@redhat.com, vgoyal@redhat.com, miklos@szeredi.hu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Fill in definitions for map, unmap and sync commands. Signed-off-by: Dr. David Alan Gilbert --- hw/virtio/vhost-user-fs.c | 129 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 123 insertions(+), 6 deletions(-) diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index da70d9cd2c..bbb15477e5 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -24,20 +24,137 @@ int vhost_user_fs_slave_map(struct vhost_dev *dev, VhostUserFSSlaveMsg *sm, int fd) { - /* TODO */ - return -1; + VHostUserFS *fs =3D VHOST_USER_FS(dev->vdev); + size_t cache_size =3D fs->conf.cache_size; + void *cache_host =3D memory_region_get_ram_ptr(&fs->cache); + + unsigned int i; + int res =3D 0; + + if (fd < 0) { + fprintf(stderr, "%s: Bad fd for map\n", __func__); + return -1; + } + + for (i =3D 0; i < VHOST_USER_FS_SLAVE_ENTRIES; i++) { + if (sm->len[i] =3D=3D 0) { + continue; + } + + if ((sm->c_offset[i] + sm->len[i]) < sm->len[i] || + (sm->c_offset[i] + sm->len[i]) > cache_size) { + fprintf(stderr, "%s: Bad offset/len for map [%d] %" + PRIx64 "+%" PRIx64 "\n", __func__, + i, sm->c_offset[i], sm->len[i]); + res =3D -1; + break; + } + + if (mmap(cache_host + sm->c_offset[i], sm->len[i], + ((sm->flags[i] & VHOST_USER_FS_FLAG_MAP_R) ? PROT_READ : = 0) | + ((sm->flags[i] & VHOST_USER_FS_FLAG_MAP_W) ? PROT_WRITE := 0), + MAP_SHARED | MAP_FIXED, + fd, sm->fd_offset[i]) !=3D (cache_host + sm->c_offset[i])= ) { + fprintf(stderr, "%s: map failed err %d [%d] %" + PRIx64 "+%" PRIx64 " from %" PRIx64 "\n", __fu= nc__, + errno, i, sm->c_offset[i], sm->len[i], + sm->fd_offset[i]); + res =3D -1; + break; + } + } + + if (res) { + /* Something went wrong, unmap them all */ + vhost_user_fs_slave_unmap(dev, sm); + } + return res; } =20 int vhost_user_fs_slave_unmap(struct vhost_dev *dev, VhostUserFSSlaveMsg *= sm) { - /* TODO */ - return -1; + VHostUserFS *fs =3D VHOST_USER_FS(dev->vdev); + size_t cache_size =3D fs->conf.cache_size; + void *cache_host =3D memory_region_get_ram_ptr(&fs->cache); + + unsigned int i; + int res =3D 0; + + /* Note even if one unmap fails we try the rest, since the effect + * is to clean up as much as possible. + */ + for (i =3D 0; i < VHOST_USER_FS_SLAVE_ENTRIES; i++) { + void *ptr; + if (sm->len[i] =3D=3D 0) { + continue; + } + + if (sm->len[i] =3D=3D ~(uint64_t)0) { + /* Special case meaning the whole arena */ + sm->len[i] =3D cache_size; + } + + if ((sm->c_offset[i] + sm->len[i]) < sm->len[i] || + (sm->c_offset[i] + sm->len[i]) > cache_size) { + fprintf(stderr, "%s: Bad offset/len for unmap [%d] %" + PRIx64 "+%" PRIx64 "\n", __func__, + i, sm->c_offset[i], sm->len[i]); + res =3D -1; + continue; + } + + ptr =3D mmap(cache_host + sm->c_offset[i], sm->len[i], + PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0); + if (ptr !=3D (cache_host + sm->c_offset[i])) { + fprintf(stderr, "%s: mmap failed (%s) [%d] %" + PRIx64 "+%" PRIx64 " from %" PRIx64 " res: %p\= n", + __func__, + strerror(errno), + i, sm->c_offset[i], sm->len[i], + sm->fd_offset[i], ptr); + res =3D -1; + } + } + + return res; } =20 int vhost_user_fs_slave_sync(struct vhost_dev *dev, VhostUserFSSlaveMsg *s= m) { - /* TODO */ - return -1; + VHostUserFS *fs =3D VHOST_USER_FS(dev->vdev); + size_t cache_size =3D fs->conf.cache_size; + void *cache_host =3D memory_region_get_ram_ptr(&fs->cache); + + unsigned int i; + int res =3D 0; + + /* Note even if one sync fails we try the rest */ + for (i =3D 0; i < VHOST_USER_FS_SLAVE_ENTRIES; i++) { + if (sm->len[i] =3D=3D 0) { + continue; + } + + if ((sm->c_offset[i] + sm->len[i]) < sm->len[i] || + (sm->c_offset[i] + sm->len[i]) > cache_size) { + fprintf(stderr, "%s: Bad offset/len for sync [%d] %" + PRIx64 "+%" PRIx64 "\n", __func__, + i, sm->c_offset[i], sm->len[i]); + res =3D -1; + continue; + } + + if (msync(cache_host + sm->c_offset[i], sm->len[i], + MS_SYNC /* ?? */)) { + fprintf(stderr, "%s: msync failed (%s) [%d] %" + PRIx64 "+%" PRIx64 " from %" PRIx64 "\n", __fu= nc__, + strerror(errno), + i, sm->c_offset[i], sm->len[i], + sm->fd_offset[i]); + res =3D -1; + } + } + + return res; } =20 =20 --=20 2.19.2 From nobody Thu May 2 02:28:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15444634491369.427292667027473; Mon, 10 Dec 2018 09:37:29 -0800 (PST) Received: from localhost ([::1]:33984 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWPUl-0002aJ-54 for importer@patchew.org; Mon, 10 Dec 2018 12:37:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46116) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWPPb-0006TT-HT for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWPPZ-0003fX-Sl for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52630) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWPPZ-0003fI-Jw for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:05 -0500 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 mx1.redhat.com (Postfix) with ESMTPS id EA14430024E0; Mon, 10 Dec 2018 17:32:04 +0000 (UTC) Received: from dgilbert-t530.redhat.com (unknown [10.36.118.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 858CF1001F5E; Mon, 10 Dec 2018 17:32:03 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2018 17:31:50 +0000 Message-Id: <20181210173151.16629-7-dgilbert@redhat.com> In-Reply-To: <20181210173151.16629-1-dgilbert@redhat.com> References: <20181210173151.16629-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 10 Dec 2018 17:32:04 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH 6/7] virtio-fs: Allow mapping of meta data version table 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: sweil@redhat.com, swhiteho@redhat.com, stefanha@redhat.com, vgoyal@redhat.com, miklos@szeredi.hu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" The 'meta data version table' is a block of shared memory mapped between multiple QEMUs and fuse daemons, so that they can be informed of metadata updates. It's typically a shmfs file, and it's specified as : -device vhost-user-fs-pci,chardev=3Dchar0,tag=3Dmyfs,cache-size=3D1G,ver= siontable=3D/dev/shm/mdvt1 It gets mapped into the PCI bar after the data cache; it's read only. Signed-off-by: Dr. David Alan Gilbert --- hw/virtio/vhost-user-fs.c | 36 ++++++++++++++++++++++ hw/virtio/virtio-pci.c | 16 ++++++++-- include/hw/virtio/vhost-user-fs.h | 4 +++ include/standard-headers/linux/virtio_fs.h | 1 + 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index bbb15477e5..a39ecd3a16 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -296,6 +296,7 @@ static void vuf_device_realize(DeviceState *dev, Error = **errp) unsigned int i; size_t len; int ret; + int mdvtfd =3D -1; =20 if (!fs->conf.chardev.chr) { error_setg(errp, "missing chardev"); @@ -338,6 +339,31 @@ static void vuf_device_realize(DeviceState *dev, Error= **errp) "no smaller than the page size"); return; } + + if (fs->conf.mdvtpath) { + struct stat statbuf; + + mdvtfd =3D open(fs->conf.mdvtpath, O_RDWR); + if (mdvtfd < 0) { + error_setg_errno(errp, errno, + "Failed to open meta-data version table '%s'", + fs->conf.mdvtpath); + + return; + } + if (fstat(mdvtfd, &statbuf) =3D=3D -1) { + error_setg_errno(errp, errno, + "Failed to stat meta-data version table '%s'", + fs->conf.mdvtpath); + close(mdvtfd); + return; + } + + fs->mdvt_size =3D statbuf.st_size; + } + fprintf(stderr, "%s: cachesize=3D%zd mdvt_size=3D%zd\n", __func__, + fs->conf.cache_size, fs->mdvt_size); + /* We need a region with some host memory, 'ram' is the easiest */ memory_region_init_ram_nomigrate(&fs->cache, OBJECT(vdev), "virtio-fs-cache", @@ -348,6 +374,15 @@ static void vuf_device_realize(DeviceState *dev, Error= **errp) mprotect(memory_region_get_ram_ptr(&fs->cache), fs->conf.cache_size, PROT_NONE); =20 + + if (mdvtfd) { + memory_region_init_ram_from_fd(&fs->mdvt, OBJECT(vdev), + "virtio-fs-mdvt", + fs->mdvt_size, true, mdvtfd, NULL); + /* The version table is read-only by the guest */ + memory_region_set_readonly(&fs->mdvt, true); + } + fs->vhost_user =3D vhost_user_init(); if (!fs->vhost_user) { error_setg(errp, "failed to initialize vhost-user"); @@ -416,6 +451,7 @@ static Property vuf_properties[] =3D { DEFINE_PROP_UINT16("queue-size", VHostUserFS, conf.queue_size, 128), DEFINE_PROP_STRING("vhostfd", VHostUserFS, conf.vhostfd), DEFINE_PROP_SIZE("cache-size", VHostUserFS, conf.cache_size, 1ull << 3= 0), + DEFINE_PROP_STRING("versiontable", VHostUserFS, conf.mdvtpath), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index e819a29fb1..d8785b78bf 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -2680,20 +2680,32 @@ static void vhost_user_fs_pci_realize(VirtIOPCIProx= y *vpci_dev, Error **errp) VHostUserFSPCI *dev =3D VHOST_USER_FS_PCI(vpci_dev); DeviceState *vdev =3D DEVICE(&dev->vdev); uint64_t cachesize; + uint64_t totalsize; =20 qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); object_property_set_bool(OBJECT(vdev), true, "realized", errp); cachesize =3D memory_region_size(&dev->vdev.cache); =20 + /* PCIe bar needs to be a power of 2 */ + totalsize =3D pow2ceil(cachesize + dev->vdev.mdvt_size); + /* The bar starts with the data/DAX cache - * Others will be added later. + * followed by the metadata cache. */ memory_region_init(&dev->cachebar, OBJECT(vpci_dev), - "vhost-fs-pci-cachebar", cachesize); + "vhost-fs-pci-cachebar", totalsize); memory_region_add_subregion(&dev->cachebar, 0, &dev->vdev.cache); virtio_pci_add_shm_cap(vpci_dev, VIRTIO_FS_PCI_CACHE_BAR, 0, cachesize, VIRTIO_FS_PCI_SHMCAP_ID_CACHE); =20 + if (dev->vdev.mdvt_size) { + memory_region_add_subregion(&dev->cachebar, cachesize, + &dev->vdev.mdvt); + virtio_pci_add_shm_cap(vpci_dev, VIRTIO_FS_PCI_CACHE_BAR, + cachesize, dev->vdev.mdvt_size, + VIRTIO_FS_PCI_SHMCAP_ID_VERTAB); + } + /* After 'realized' so the memory region exists */ pci_register_bar(&vpci_dev->pci_dev, VIRTIO_FS_PCI_CACHE_BAR, PCI_BASE_ADDRESS_SPACE_MEMORY | diff --git a/include/hw/virtio/vhost-user-fs.h b/include/hw/virtio/vhost-us= er-fs.h index 9989bcd9e7..281ae0a52d 100644 --- a/include/hw/virtio/vhost-user-fs.h +++ b/include/hw/virtio/vhost-user-fs.h @@ -48,6 +48,7 @@ typedef struct { uint16_t queue_size; char *vhostfd; size_t cache_size; + char *mdvtpath; } VHostUserFSConf; =20 typedef struct { @@ -60,6 +61,9 @@ typedef struct { =20 /*< public >*/ MemoryRegion cache; + /* Metadata version table */ + size_t mdvt_size; + MemoryRegion mdvt; } VHostUserFS; =20 /* Callbacks from the vhost-user code for slave commands */ diff --git a/include/standard-headers/linux/virtio_fs.h b/include/standard-= headers/linux/virtio_fs.h index b5f137ca79..77fa651073 100644 --- a/include/standard-headers/linux/virtio_fs.h +++ b/include/standard-headers/linux/virtio_fs.h @@ -42,5 +42,6 @@ struct virtio_fs_config { =20 /* For the id field in virtio_pci_shm_cap */ #define VIRTIO_FS_PCI_SHMCAP_ID_CACHE 0 +#define VIRTIO_FS_PCI_SHMCAP_ID_VERTAB 1 =20 #endif /* _LINUX_VIRTIO_FS_H */ --=20 2.19.2 From nobody Thu May 2 02:28:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544463399990148.17792786132816; Mon, 10 Dec 2018 09:36:39 -0800 (PST) Received: from localhost ([::1]:33980 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWPTy-00021k-Kr for importer@patchew.org; Mon, 10 Dec 2018 12:36:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46137) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWPPd-0006VQ-BG for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWPPb-0003gT-NQ for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52660) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWPPb-0003fx-B5 for qemu-devel@nongnu.org; Mon, 10 Dec 2018 12:32:07 -0500 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 mx1.redhat.com (Postfix) with ESMTPS id 9195430024ED; Mon, 10 Dec 2018 17:32:06 +0000 (UTC) Received: from dgilbert-t530.redhat.com (unknown [10.36.118.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33BB51001F5E; Mon, 10 Dec 2018 17:32:05 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2018 17:31:51 +0000 Message-Id: <20181210173151.16629-8-dgilbert@redhat.com> In-Reply-To: <20181210173151.16629-1-dgilbert@redhat.com> References: <20181210173151.16629-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 10 Dec 2018 17:32:06 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH 7/7] virtio-fs: Allow mapping of journal 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: sweil@redhat.com, swhiteho@redhat.com, stefanha@redhat.com, vgoyal@redhat.com, miklos@szeredi.hu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" The 'journal' is a shared block of RAM between QEMU and it's fuse daemon. It's typically a shmfs file and it's specified as: -device vhost-user-fs-pci,chardev=3Dchar0,tag=3Dmyfs,cache-size=3D1G,versiontable= =3D/dev/shm/mdvt1,journal=3D/dev/shm/journal1 It gets mapped into the PCI bar after the version table. Signed-off-by: Dr. David Alan Gilbert --- hw/virtio/vhost-user-fs.c | 35 ++++++++++++++++++++-- hw/virtio/virtio-pci.c | 14 ++++++++- include/hw/virtio/vhost-user-fs.h | 4 +++ include/standard-headers/linux/virtio_fs.h | 1 + 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index a39ecd3a16..b263f43c60 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -297,6 +297,7 @@ static void vuf_device_realize(DeviceState *dev, Error = **errp) size_t len; int ret; int mdvtfd =3D -1; + int journalfd =3D -1; =20 if (!fs->conf.chardev.chr) { error_setg(errp, "missing chardev"); @@ -361,8 +362,31 @@ static void vuf_device_realize(DeviceState *dev, Error= **errp) =20 fs->mdvt_size =3D statbuf.st_size; } - fprintf(stderr, "%s: cachesize=3D%zd mdvt_size=3D%zd\n", __func__, - fs->conf.cache_size, fs->mdvt_size); + if (fs->conf.journalpath) { + struct stat statbuf; + + journalfd =3D open(fs->conf.journalpath, O_RDWR); + if (journalfd < 0) { + error_setg_errno(errp, errno, + "Failed to open journal '%s'", + fs->conf.journalpath); + + close(mdvtfd); + return; + } + if (fstat(journalfd, &statbuf) =3D=3D -1) { + error_setg_errno(errp, errno, + "Failed to stat journal '%s'", + fs->conf.journalpath); + close(mdvtfd); + close(journalfd); + return; + } + + fs->journal_size =3D statbuf.st_size; + } + fprintf(stderr, "%s: cachesize=3D%zd mdvt_size=3D%zd journal_size=3D%z= d\n", + __func__, fs->conf.cache_size, fs->mdvt_size, fs->journal_size= ); =20 /* We need a region with some host memory, 'ram' is the easiest */ memory_region_init_ram_nomigrate(&fs->cache, OBJECT(vdev), @@ -383,6 +407,12 @@ static void vuf_device_realize(DeviceState *dev, Error= **errp) memory_region_set_readonly(&fs->mdvt, true); } =20 + if (journalfd) { + memory_region_init_ram_from_fd(&fs->journal, OBJECT(vdev), + "virtio-fs-journal", + fs->journal_size, true, journalfd, NULL); + } + fs->vhost_user =3D vhost_user_init(); if (!fs->vhost_user) { error_setg(errp, "failed to initialize vhost-user"); @@ -452,6 +482,7 @@ static Property vuf_properties[] =3D { DEFINE_PROP_STRING("vhostfd", VHostUserFS, conf.vhostfd), DEFINE_PROP_SIZE("cache-size", VHostUserFS, conf.cache_size, 1ull << 3= 0), DEFINE_PROP_STRING("versiontable", VHostUserFS, conf.mdvtpath), + DEFINE_PROP_STRING("journal", VHostUserFS, conf.journalpath), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index d8785b78bf..a46dd5a784 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -2687,10 +2687,12 @@ static void vhost_user_fs_pci_realize(VirtIOPCIProx= y *vpci_dev, Error **errp) cachesize =3D memory_region_size(&dev->vdev.cache); =20 /* PCIe bar needs to be a power of 2 */ - totalsize =3D pow2ceil(cachesize + dev->vdev.mdvt_size); + totalsize =3D pow2ceil(cachesize + dev->vdev.mdvt_size + + dev->vdev.journal_size); =20 /* The bar starts with the data/DAX cache * followed by the metadata cache. + * followed by the journal */ memory_region_init(&dev->cachebar, OBJECT(vpci_dev), "vhost-fs-pci-cachebar", totalsize); @@ -2706,6 +2708,16 @@ static void vhost_user_fs_pci_realize(VirtIOPCIProxy= *vpci_dev, Error **errp) VIRTIO_FS_PCI_SHMCAP_ID_VERTAB); } =20 + if (dev->vdev.journal_size) { + memory_region_add_subregion(&dev->cachebar, + cachesize + dev->vdev.mdvt_size, + &dev->vdev.journal); + virtio_pci_add_shm_cap(vpci_dev, VIRTIO_FS_PCI_CACHE_BAR, + cachesize + dev->vdev.mdvt_size, + dev->vdev.journal_size, + VIRTIO_FS_PCI_SHMCAP_ID_JOURNAL); + } + /* After 'realized' so the memory region exists */ pci_register_bar(&vpci_dev->pci_dev, VIRTIO_FS_PCI_CACHE_BAR, PCI_BASE_ADDRESS_SPACE_MEMORY | diff --git a/include/hw/virtio/vhost-user-fs.h b/include/hw/virtio/vhost-us= er-fs.h index 281ae0a52d..6d9f74a543 100644 --- a/include/hw/virtio/vhost-user-fs.h +++ b/include/hw/virtio/vhost-user-fs.h @@ -49,6 +49,7 @@ typedef struct { char *vhostfd; size_t cache_size; char *mdvtpath; + char *journalpath; } VHostUserFSConf; =20 typedef struct { @@ -64,6 +65,9 @@ typedef struct { /* Metadata version table */ size_t mdvt_size; MemoryRegion mdvt; + /* Journal */ + size_t journal_size; + MemoryRegion journal; } VHostUserFS; =20 /* Callbacks from the vhost-user code for slave commands */ diff --git a/include/standard-headers/linux/virtio_fs.h b/include/standard-= headers/linux/virtio_fs.h index 77fa651073..0242f2a06e 100644 --- a/include/standard-headers/linux/virtio_fs.h +++ b/include/standard-headers/linux/virtio_fs.h @@ -43,5 +43,6 @@ struct virtio_fs_config { /* For the id field in virtio_pci_shm_cap */ #define VIRTIO_FS_PCI_SHMCAP_ID_CACHE 0 #define VIRTIO_FS_PCI_SHMCAP_ID_VERTAB 1 +#define VIRTIO_FS_PCI_SHMCAP_ID_JOURNAL 2 =20 #endif /* _LINUX_VIRTIO_FS_H */ --=20 2.19.2