From: Jason Wang <jasowang@redhat.com>
To: Jason Gunthorpe <jgg@mellanox.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: Fri, 21 Feb 2020 15:57:29 +0800 [thread overview]
Message-ID: <6c341a77-a297-b7c7-dea5-b3f7b920b1f3@redhat.com> (raw)
In-Reply-To: <20200220151215.GU23930@mellanox.com>
On 2020/2/20 下午11:12, Jason Gunthorpe wrote:
> 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 ?
I think it works.
>> + 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.
Yes, that looks simpler.
>
>> +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 ?
Not necessary but doesn't harm, will remove this.
Thanks
>
> Jason
>
next prev parent reply other threads:[~2020-02-21 8:41 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
2020-02-21 7:57 ` Jason Wang [this message]
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=6c341a77-a297-b7c7-dea5-b3f7b920b1f3@redhat.com \
--to=jasowang@redhat.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=jgg@mellanox.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
all inboxes | Powered by JetHome®