Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5125930yba; Wed, 10 Apr 2019 11:56:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqz0R5Y22eX0sePKn4M+4+xx32K6Nwv23Fq+2vuKN06FEChkeiEq2NcWeTyi/Sggg5LmiZQA X-Received: by 2002:aa7:9294:: with SMTP id j20mr45182739pfa.64.1554922562162; Wed, 10 Apr 2019 11:56:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554922562; cv=none; d=google.com; s=arc-20160816; b=tG2CBQu6v7zFsdq7zL9UXuru7KQ3QixBu7MAUr43Rctq+az1RvKMvTy75YJk7Zet1T m8nZ9PIFWRfJQZ3kF19ww0uCk+rlRe6MXuchtwosjx4X/M6BACi2SXySREP5YqpYdqyy glt63GZmqeUXjZOsVI9WJfihALLnJJmegO/0fmfYkxNXRwPx5OrKT6W6Zo/2XOoxrEPV /40X1vMA43J0JRrLe22DFfULkMBydFb4em39P1zp73T3hikmXXsVoh+uDZm53Ykr/jp3 9ffrhBzfOcvsznaYiMFR5E5pXReNjdPXlaThnlseA4S5K6p6fz5uDywiNLL53NNN+rHM tq1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date; bh=OJl0wPi6aeTmuBIFF0hMx6YHC2tYeVy46Darowg24sQ=; b=xQ0Z3Dt732CfnEQwRDJyj8Bbk1UpkZUjAUxBOtK8A+rqpSl58nQOfcRTu6VtLNqXms VhsdZy75avCYe0hLQFJB1b0ksTBimoApc+oEL4VKIMUnFubuKpAZRIMMod2go8bf3wlx Y87CArIYacWTTOuyH9vUjkYMmUHVfUr5kgF515esmaYNsNbcWqXCoDSHhBw3JEzj4f48 /XyuPcXHkI/g0meZjGQclo04GkznCaVMXJ7Ds4WQwRQzj1MUHOOLpHjTRWVmcvdS+tMF wzVgj9L+zBXfo/+HKsN5ZpHxW2jAwHq19Biu0zPt3cr4MAUiyjb9JPWMrroTQWyNlp71 uWsQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d186si33696015pfa.218.2019.04.10.11.55.46; Wed, 10 Apr 2019 11:56:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731441AbfDJPiC (ORCPT + 99 others); Wed, 10 Apr 2019 11:38:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37336 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726494AbfDJPiC (ORCPT ); Wed, 10 Apr 2019 11:38:02 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D956181114; Wed, 10 Apr 2019 15:38:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BD0155DA5B; Wed, 10 Apr 2019 15:38:00 +0000 (UTC) Received: from zmail21.collab.prod.int.phx2.redhat.com (zmail21.collab.prod.int.phx2.redhat.com [10.5.83.24]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7000F3FA45; Wed, 10 Apr 2019 15:38:00 +0000 (UTC) Date: Wed, 10 Apr 2019 11:38:00 -0400 (EDT) From: Pankaj Gupta To: Cornelia Huck Cc: linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-acpi@vger.kernel.org, qemu-devel@nongnu.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, dan j williams , zwisler@kernel.org, vishal l verma , dave jiang , mst@redhat.com, jasowang@redhat.com, willy@infradead.org, rjw@rjwysocki.net, hch@infradead.org, lenb@kernel.org, jack@suse.cz, tytso@mit.edu, adilger kernel , darrick wong , lcapitulino@redhat.com, kwolf@redhat.com, imammedo@redhat.com, jmoyer@redhat.com, nilal@redhat.com, riel@surriel.com, stefanha@redhat.com, aarcange@redhat.com, david@redhat.com, david@fromorbit.com, xiaoguangrong eric , pbonzini@redhat.com, kilobyte@angband.pl, yuval shaia Message-ID: <1663006162.20832248.1554910680080.JavaMail.zimbra@redhat.com> In-Reply-To: <20190410142426.5bf0d9a4.cohuck@redhat.com> References: <20190410040826.24371-1-pagupta@redhat.com> <20190410040826.24371-3-pagupta@redhat.com> <20190410142426.5bf0d9a4.cohuck@redhat.com> Subject: Re: [PATCH v5 2/5] virtio-pmem: Add virtio pmem driver MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.116.117, 10.4.195.26] Thread-Topic: virtio-pmem: Add virtio pmem driver Thread-Index: ni96j4d6FUDPJPNtE4chnh/uKdN03w== X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 10 Apr 2019 15:38:01 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > > > This patch adds virtio-pmem driver for KVM guest. > > > > Guest reads the persistent memory range information from > > Qemu over VIRTIO and registers it on nvdimm_bus. It also > > creates a nd_region object with the persistent memory > > range information so that existing 'nvdimm/pmem' driver > > can reserve this into system memory map. This way > > 'virtio-pmem' driver uses existing functionality of pmem > > driver to register persistent memory compatible for DAX > > capable filesystems. > > > > This also provides function to perform guest flush over > > VIRTIO from 'pmem' driver when userspace performs flush > > on DAX memory range. > > > > Signed-off-by: Pankaj Gupta > > --- > > drivers/nvdimm/virtio_pmem.c | 88 ++++++++++++++++++++++ > > drivers/virtio/Kconfig | 10 +++ > > drivers/virtio/Makefile | 1 + > > drivers/virtio/pmem.c | 124 +++++++++++++++++++++++++++++++ > > include/linux/virtio_pmem.h | 60 +++++++++++++++ > > include/uapi/linux/virtio_ids.h | 1 + > > include/uapi/linux/virtio_pmem.h | 10 +++ > > 7 files changed, 294 insertions(+) > > create mode 100644 drivers/nvdimm/virtio_pmem.c > > create mode 100644 drivers/virtio/pmem.c > > create mode 100644 include/linux/virtio_pmem.h > > create mode 100644 include/uapi/linux/virtio_pmem.h > > > (...) > > diff --git a/drivers/virtio/pmem.c b/drivers/virtio/pmem.c > > new file mode 100644 > > index 000000000000..cc9de9589d56 > > --- /dev/null > > +++ b/drivers/virtio/pmem.c > > @@ -0,0 +1,124 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * virtio_pmem.c: Virtio pmem Driver > > + * > > + * Discovers persistent memory range information > > + * from host and registers the virtual pmem device > > + * with libnvdimm core. > > + */ > > +#include > > +#include <../../drivers/nvdimm/nd.h> > > + > > +static struct virtio_device_id id_table[] = { > > + { VIRTIO_ID_PMEM, VIRTIO_DEV_ANY_ID }, > > + { 0 }, > > +}; > > + > > + /* Initialize virt queue */ > > +static int init_vq(struct virtio_pmem *vpmem) > > IMHO, you don't gain much by splitting off this function... o.k. I kept this for better code structure. > > > +{ > > + struct virtqueue *vq; > > + > > + /* single vq */ > > + vpmem->req_vq = vq = virtio_find_single_vq(vpmem->vdev, > > + host_ack, "flush_queue"); > > + if (IS_ERR(vq)) > > + return PTR_ERR(vq); > > I'm personally not a fan of chained assignments... I think I'd just > drop the 'vq' variable and operate on vpmem->req_vq directly. Sure. > > > + > > + spin_lock_init(&vpmem->pmem_lock); > > + INIT_LIST_HEAD(&vpmem->req_list); > > + > > + return 0; > > +}; > > + > > +static int virtio_pmem_probe(struct virtio_device *vdev) > > +{ > > + int err = 0; > > + struct resource res; > > + struct virtio_pmem *vpmem; > > + struct nvdimm_bus *nvdimm_bus; > > + struct nd_region_desc ndr_desc = {}; > > + int nid = dev_to_node(&vdev->dev); > > + struct nd_region *nd_region; > > + > > + if (!vdev->config->get) { > > + dev_err(&vdev->dev, "%s failure: config disabled\n", > > Maybe s/config disabled/config access disabled/ ? That seems to be the > more common message. This is better. > > > + __func__); > > + return -EINVAL; > > + } > > + > > + vdev->priv = vpmem = devm_kzalloc(&vdev->dev, sizeof(*vpmem), > > + GFP_KERNEL); > > Here, the vpmem variable makes sense for convenience, but I'm again not > a fan of the chaining :) Sure will change :) > > > + if (!vpmem) { > > + err = -ENOMEM; > > + goto out_err; > > + } > > + > > + vpmem->vdev = vdev; > > + err = init_vq(vpmem); > > + if (err) > > + goto out_err; > > + > > + virtio_cread(vpmem->vdev, struct virtio_pmem_config, > > + start, &vpmem->start); > > + virtio_cread(vpmem->vdev, struct virtio_pmem_config, > > + size, &vpmem->size); > > + > > + res.start = vpmem->start; > > + res.end = vpmem->start + vpmem->size-1; > > + vpmem->nd_desc.provider_name = "virtio-pmem"; > > + vpmem->nd_desc.module = THIS_MODULE; > > + > > + vpmem->nvdimm_bus = nvdimm_bus = nvdimm_bus_register(&vdev->dev, > > + &vpmem->nd_desc); > > And here :) Sure. > > > + if (!nvdimm_bus) > > + goto out_vq; > > + > > + dev_set_drvdata(&vdev->dev, nvdimm_bus); > > + > > + ndr_desc.res = &res; > > + ndr_desc.numa_node = nid; > > + ndr_desc.flush = virtio_pmem_flush; > > + set_bit(ND_REGION_PAGEMAP, &ndr_desc.flags); > > + set_bit(ND_REGION_ASYNC, &ndr_desc.flags); > > + nd_region = nvdimm_pmem_region_create(nvdimm_bus, &ndr_desc); > > + nd_region->provider_data = dev_to_virtio > > + (nd_region->dev.parent->parent); > > Isn't it clear that this parent chain will always end up at &vdev->dev? Yes, It will resolve to &vdev->dev. > Maybe simply set ->provider_data to vdev directly? (Does it need to > grab a reference count of the device, BTW?) reference is already taken when registering the device with nvdimm_bus. > > > + > > + if (!nd_region) > > + goto out_nd; > > Probably better to do this check before you access nd_region's > members :) ah Sorry! Will correct this. > > > + > > + return 0; > > +out_nd: > > + err = -ENXIO; > > + nvdimm_bus_unregister(nvdimm_bus); > > +out_vq: > > + vdev->config->del_vqs(vdev); > > +out_err: > > + dev_err(&vdev->dev, "failed to register virtio pmem memory\n"); > > + return err; > > +} > > + > > +static void virtio_pmem_remove(struct virtio_device *vdev) > > +{ > > + struct virtio_pmem *vpmem = vdev->priv; > > + struct nvdimm_bus *nvdimm_bus = dev_get_drvdata(&vdev->dev); > > + > > + nvdimm_bus_unregister(nvdimm_bus); > > I haven't followed this around the nvdimm code, but is the nd_region > you created during probe cleaned up automatically, or would you need to > do something here? 'nvdimm_bus_unregister' does that. > > > + vdev->config->del_vqs(vdev); > > + vdev->config->reset(vdev); > > + kfree(vpmem); > > You allocated vpmem via devm_kzalloc; isn't it freed automatically on > remove? yes. Will remove free(vpmem). > > > +} > > + > > +static struct virtio_driver virtio_pmem_driver = { > > + .driver.name = KBUILD_MODNAME, > > + .driver.owner = THIS_MODULE, > > + .id_table = id_table, > > + .probe = virtio_pmem_probe, > > + .remove = virtio_pmem_remove, > > +}; > > + > > +module_virtio_driver(virtio_pmem_driver); > > +MODULE_DEVICE_TABLE(virtio, id_table); > > +MODULE_DESCRIPTION("Virtio pmem driver"); > > +MODULE_LICENSE("GPL"); > > Only looked at this from the general virtio driver angle; seems fine > apart from some easy-to-fix issues and some personal style preference > things. Thank you for the review. Best regards, Pankaj >