From: Jason Gunthorpe <jgg@mellanox.com>
To: Jason Wang <jasowang@redhat.com>
Cc: "mst@redhat.com" <mst@redhat.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"virtualization@lists.linux-foundation.org"
<virtualization@lists.linux-foundation.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"tiwei.bie@intel.com" <tiwei.bie@intel.com>,
"maxime.coquelin@redhat.com" <maxime.coquelin@redhat.com>,
"cunming.liang@intel.com" <cunming.liang@intel.com>,
"zhihong.wang@intel.com" <zhihong.wang@intel.com>,
"rob.miller@broadcom.com" <rob.miller@broadcom.com>,
"xiao.w.wang@intel.com" <xiao.w.wang@intel.com>,
"haotian.wang@sifive.com" <haotian.wang@sifive.com>,
"lingshan.zhu@intel.com" <lingshan.zhu@intel.com>,
"eperezma@redhat.com" <eperezma@redhat.com>,
"lulu@redhat.com" <lulu@redhat.com>,
Parav Pandit <parav@mellanox.com>,
"kevin.tian@intel.com" <kevin.tian@intel.com>,
"stefanha@redhat.com" <stefanha@redhat.com>,
"rdunlap@infradead.org" <rdunlap@infradead.org>,
"hch@infradead.org" <hch@infradead.org>,
"aadam@redhat.com" <aadam@redhat.com>,
Jiri Pirko <jiri@mellanox.com>,
Shahaf Shuler <shahafs@mellanox.com>,
"hanand@xilinx.com" <hanand@xilinx.com>,
"mhabets@solarflare.com" <mhabets@solarflare.com>
Subject: Re: [PATCH V4 5/5] vdpasim: vDPA device simulator
Date: Thu, 20 Feb 2020 15:12:18 +0000 [thread overview]
Message-ID: <20200220151215.GU23930@mellanox.com> (raw)
In-Reply-To: <20200220061141.29390-6-jasowang@redhat.com>
On Thu, Feb 20, 2020 at 02:11:41PM +0800, Jason Wang wrote:
> +static void vdpasim_device_release(struct device *dev)
> +{
> + struct vdpasim *vdpasim = dev_to_sim(dev);
> +
> + cancel_work_sync(&vdpasim->work);
> + kfree(vdpasim->buffer);
> + vhost_iotlb_free(vdpasim->iommu);
> + kfree(vdpasim);
> +}
> +
> +static struct vdpasim *vdpasim_create(void)
> +{
> + struct virtio_net_config *config;
> + struct vhost_iotlb *iommu;
> + struct vdpasim *vdpasim;
> + struct device *dev;
> + void *buffer;
> + int ret = -ENOMEM;
> +
> + iommu = vhost_iotlb_alloc(2048, 0);
> + if (!iommu)
> + goto err;
> +
> + buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
> + if (!buffer)
> + goto err_buffer;
> +
> + vdpasim = kzalloc(sizeof(*vdpasim), GFP_KERNEL);
> + if (!vdpasim)
> + goto err_alloc;
> +
> + vdpasim->buffer = buffer;
> + vdpasim->iommu = iommu;
> +
> + config = &vdpasim->config;
> + config->mtu = 1500;
> + config->status = VIRTIO_NET_S_LINK_UP;
> + eth_random_addr(config->mac);
> +
> + INIT_WORK(&vdpasim->work, vdpasim_work);
> + spin_lock_init(&vdpasim->lock);
> +
> + vringh_set_iotlb(&vdpasim->vqs[0].vring, vdpasim->iommu);
> + vringh_set_iotlb(&vdpasim->vqs[1].vring, vdpasim->iommu);
> +
> + dev = &vdpasim->dev;
> + dev->release = vdpasim_device_release;
> + dev->coherent_dma_mask = DMA_BIT_MASK(64);
> + set_dma_ops(dev, &vdpasim_dma_ops);
> + dev_set_name(dev, "%s", VDPASIM_NAME);
> +
> + ret = device_register(&vdpasim->dev);
> + if (ret)
> + goto err_init;
It is a bit weird to be creating this dummy parent, couldn't this be
done by just passing a NULL parent to vdpa_alloc_device, doing
set_dma_ops() on the vdpasim->vdpa->dev and setting dma_device to
vdpasim->vdpa->dev ?
> + vdpasim->vdpa = vdpa_alloc_device(dev, dev, &vdpasim_net_config_ops);
> + if (ret)
> + goto err_vdpa;
> + ret = vdpa_register_device(vdpasim->vdpa);
> + if (ret)
> + goto err_register;
> +
> + return vdpasim;
> +
> +err_register:
> + put_device(&vdpasim->vdpa->dev);
> +err_vdpa:
> + device_del(&vdpasim->dev);
> + goto err;
> +err_init:
> + put_device(&vdpasim->dev);
> + goto err;
If you do the vdmasim alloc first, and immediately do
device_initialize() then all the failure paths can do put_device
instead of having this ugly goto unwind split. Just check for
vdpasim->iommu == NULL during release.
> +static int __init vdpasim_dev_init(void)
> +{
> + vdpasim_dev = vdpasim_create();
> +
> + if (!IS_ERR(vdpasim_dev))
> + return 0;
> +
> + return PTR_ERR(vdpasim_dev);
> +}
> +
> +static int vdpasim_device_remove_cb(struct device *dev, void *data)
> +{
> + struct vdpa_device *vdpa = dev_to_vdpa(dev);
> +
> + vdpa_unregister_device(vdpa);
> +
> + return 0;
> +}
> +
> +static void __exit vdpasim_dev_exit(void)
> +{
> + device_for_each_child(&vdpasim_dev->dev, NULL,
> + vdpasim_device_remove_cb);
Why the loop? There is only one device, and it is in the global
varaible vdmasim_dev ?
Jason
next prev parent reply other threads:[~2020-02-20 15:12 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-20 6:11 [PATCH V4 0/5] vDPA support Jason Wang
2020-02-20 6:11 ` [PATCH V4 1/5] vhost: factor out IOTLB Jason Wang
2020-02-20 6:11 ` [PATCH V4 2/5] vringh: IOTLB support Jason Wang
2020-02-20 6:11 ` [PATCH V4 3/5] vDPA: introduce vDPA bus Jason Wang
2020-02-20 15:14 ` Jason Gunthorpe
2020-02-21 7:54 ` Jason Wang
2020-02-24 6:14 ` Harpreet Singh Anand
2020-02-24 6:48 ` Jason Wang
2020-02-20 6:11 ` [PATCH V4 4/5] virtio: introduce a vDPA based transport Jason Wang
2020-02-20 15:19 ` Jason Gunthorpe
2020-02-21 8:06 ` Jason Wang
2020-02-20 6:11 ` [PATCH V4 5/5] vdpasim: vDPA device simulator Jason Wang
2020-02-20 15:12 ` Jason Gunthorpe [this message]
2020-02-21 7:57 ` Jason Wang
2020-02-26 6:12 ` Jason Wang
2020-02-26 17:19 ` Jason Gunthorpe
2020-02-21 8:33 ` Harpreet Singh Anand
2020-02-21 8:50 ` Jason Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200220151215.GU23930@mellanox.com \
--to=jgg@mellanox.com \
--cc=aadam@redhat.com \
--cc=cunming.liang@intel.com \
--cc=eperezma@redhat.com \
--cc=hanand@xilinx.com \
--cc=haotian.wang@sifive.com \
--cc=hch@infradead.org \
--cc=jasowang@redhat.com \
--cc=jiri@mellanox.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=lingshan.zhu@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lulu@redhat.com \
--cc=maxime.coquelin@redhat.com \
--cc=mhabets@solarflare.com \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=parav@mellanox.com \
--cc=rdunlap@infradead.org \
--cc=rob.miller@broadcom.com \
--cc=shahafs@mellanox.com \
--cc=stefanha@redhat.com \
--cc=tiwei.bie@intel.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=xiao.w.wang@intel.com \
--cc=zhihong.wang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).