From patchwork Wed Apr 14 15:51:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dr. David Alan Gilbert" X-Patchwork-Id: 12203281 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 967BEC433ED for ; Wed, 14 Apr 2021 16:02:47 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E56A161220 for ; Wed, 14 Apr 2021 16:02:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E56A161220 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lWhyX-0008Fk-W3 for qemu-devel@archiver.kernel.org; Wed, 14 Apr 2021 12:02:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34218) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWho8-0007ql-1V for qemu-devel@nongnu.org; Wed, 14 Apr 2021 11:52:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24184) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWho6-0000LP-6X for qemu-devel@nongnu.org; Wed, 14 Apr 2021 11:51:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618415514; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y/kl2aHuxlMmmxeaeoocdR+zk0WlDLgKZZlO92j7sgc=; b=UD+uxBwE8pDsJSIoNbZP39eMBc1nX9lsJUNgEjeFpBgt24o6J9ululBwyTdEa7JFwxwfhg T5DiCySPNpqt1/cAZXnkNcuGyiMlNmy8n7+NhVCCL5n07nao08qwPOUvppc/rqx8kA7NQn 5A3TG9THlp//F5Nd2dzVUOMyVaxgW/M= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-326-uU9Xiu3lNSalsSFgnyzJ8Q-1; Wed, 14 Apr 2021 11:51:53 -0400 X-MC-Unique: uU9Xiu3lNSalsSFgnyzJ8Q-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 43F7087A83F for ; Wed, 14 Apr 2021 15:51:52 +0000 (UTC) Received: from dgilbert-t580.localhost (ovpn-115-158.ams2.redhat.com [10.36.115.158]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3404B610A8; Wed, 14 Apr 2021 15:51:51 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, stefanha@redhat.com, vgoyal@redhat.com, virtio-fs@redhat.com Subject: [PATCH v2 07/25] DAX: virtio-fs: Add cache BAR Date: Wed, 14 Apr 2021 16:51:19 +0100 Message-Id: <20210414155137.46522-8-dgilbert@redhat.com> In-Reply-To: <20210414155137.46522-1-dgilbert@redhat.com> References: <20210414155137.46522-1-dgilbert@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dgilbert@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: "Dr. David Alan Gilbert" Add a cache BAR into which files will be directly mapped. The size can be set with the cache-size= property, e.g. -device vhost-user-fs-pci,chardev=char0,tag=myfs,cache-size=16G The default is no cache. Signed-off-by: Dr. David Alan Gilbert with PPC fixes by: Signed-off-by: Fabiano Rosas --- hw/virtio/vhost-user-fs-pci.c | 32 +++++++++++++++++++++++++++++++ hw/virtio/vhost-user-fs.c | 32 +++++++++++++++++++++++++++++++ include/hw/virtio/vhost-user-fs.h | 2 ++ 3 files changed, 66 insertions(+) diff --git a/hw/virtio/vhost-user-fs-pci.c b/hw/virtio/vhost-user-fs-pci.c index 2ed8492b3f..20e447631f 100644 --- a/hw/virtio/vhost-user-fs-pci.c +++ b/hw/virtio/vhost-user-fs-pci.c @@ -12,14 +12,19 @@ */ #include "qemu/osdep.h" +#include "qapi/error.h" #include "hw/qdev-properties.h" #include "hw/virtio/vhost-user-fs.h" #include "virtio-pci.h" #include "qom/object.h" +#include "standard-headers/linux/virtio_fs.h" + +#define VIRTIO_FS_PCI_CACHE_BAR 2 struct VHostUserFSPCI { VirtIOPCIProxy parent_obj; VHostUserFS vdev; + MemoryRegion cachebar; }; typedef struct VHostUserFSPCI VHostUserFSPCI; @@ -38,7 +43,9 @@ static Property vhost_user_fs_pci_properties[] = { static void vhost_user_fs_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) { VHostUserFSPCI *dev = VHOST_USER_FS_PCI(vpci_dev); + bool modern_pio = vpci_dev->flags & VIRTIO_PCI_FLAG_MODERN_PIO_NOTIFY; DeviceState *vdev = DEVICE(&dev->vdev); + uint64_t cachesize; if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) { /* Also reserve config change and hiprio queue vectors */ @@ -46,6 +53,31 @@ static void vhost_user_fs_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) } qdev_realize(vdev, BUS(&vpci_dev->bus), errp); + cachesize = dev->vdev.conf.cache_size; + + if (cachesize && modern_pio) { + error_setg(errp, "DAX Cache can not be used together with modern_pio"); + return; + } + + /* + * The bar starts with the data/DAX cache + * Others will be added later. + */ + memory_region_init(&dev->cachebar, OBJECT(vpci_dev), + "vhost-user-fs-pci-cachebar", cachesize); + if (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_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); + } } static void vhost_user_fs_pci_class_init(ObjectClass *klass, void *data) diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index 6f7f91533d..dd0a02aa99 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -35,6 +35,16 @@ static const int user_feature_bits[] = { VHOST_INVALID_FEATURE_BIT }; +/* + * The powerpc kernel code expects the memory to be accessible during + * addition/removal. + */ +#if defined(TARGET_PPC64) && defined(CONFIG_LINUX) +#define DAX_WINDOW_PROT PROT_READ +#else +#define DAX_WINDOW_PROT PROT_NONE +#endif + static void vuf_get_config(VirtIODevice *vdev, uint8_t *config) { VHostUserFS *fs = VHOST_USER_FS(vdev); @@ -175,6 +185,7 @@ static void vuf_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); VHostUserFS *fs = VHOST_USER_FS(dev); + void *cache_ptr; unsigned int i; size_t len; int ret; @@ -214,6 +225,26 @@ static void vuf_device_realize(DeviceState *dev, Error **errp) VIRTQUEUE_MAX_SIZE); return; } + if (fs->conf.cache_size && + (!is_power_of_2(fs->conf.cache_size) || + fs->conf.cache_size < qemu_real_host_page_size)) { + error_setg(errp, "cache-size property must be a power of 2 " + "no smaller than the page size"); + return; + } + if (fs->conf.cache_size) { + /* Anonymous, private memory is not counted as overcommit */ + cache_ptr = mmap(NULL, fs->conf.cache_size, DAX_WINDOW_PROT, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + if (cache_ptr == MAP_FAILED) { + error_setg(errp, "Unable to mmap blank cache"); + return; + } + + memory_region_init_ram_ptr(&fs->cache, OBJECT(vdev), + "virtio-fs-cache", + fs->conf.cache_size, cache_ptr); + } if (!vhost_user_init(&fs->vhost_user, &fs->conf.chardev, errp)) { return; @@ -289,6 +320,7 @@ static Property vuf_properties[] = { DEFINE_PROP_UINT16("num-request-queues", VHostUserFS, conf.num_request_queues, 1), DEFINE_PROP_UINT16("queue-size", VHostUserFS, conf.queue_size, 128), + DEFINE_PROP_SIZE("cache-size", VHostUserFS, conf.cache_size, 0), DEFINE_PROP_END_OF_LIST(), }; diff --git a/include/hw/virtio/vhost-user-fs.h b/include/hw/virtio/vhost-user-fs.h index 0d62834c25..04596799e3 100644 --- a/include/hw/virtio/vhost-user-fs.h +++ b/include/hw/virtio/vhost-user-fs.h @@ -28,6 +28,7 @@ typedef struct { char *tag; uint16_t num_request_queues; uint16_t queue_size; + uint64_t cache_size; } VHostUserFSConf; struct VHostUserFS { @@ -42,6 +43,7 @@ struct VHostUserFS { int32_t bootindex; /*< public >*/ + MemoryRegion cache; }; #endif /* _QEMU_VHOST_USER_FS_H */