All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: Jason Gunthorpe <jgg@mellanox.com>
Cc: mst@redhat.com, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org, virtualization@lists.linux-foundation.org,
	netdev@vger.kernel.org, tiwei.bie@intel.com,
	maxime.coquelin@redhat.com, cunming.liang@intel.com,
	zhihong.wang@intel.com, rob.miller@broadcom.com,
	xiao.w.wang@intel.com, haotian.wang@sifive.com,
	lingshan.zhu@intel.com, eperezma@redhat.com, lulu@redhat.com,
	parav@mellanox.com, kevin.tian@intel.com, stefanha@redhat.com,
	rdunlap@infradead.org, hch@infradead.org, aadam@redhat.com,
	jiri@mellanox.com, shahafs@mellanox.com, hanand@xilinx.com,
	mhabets@solarflare.com
Subject: Re: [PATCH V2 5/5] vdpasim: vDPA device simulator
Date: Wed, 12 Feb 2020 16:27:16 +0800	[thread overview]
Message-ID: <3dbadf4e-c4c5-22cc-f970-f25fa42c13d8@redhat.com> (raw)
In-Reply-To: <20200211135254.GJ4271@mellanox.com>


On 2020/2/11 下午9:52, Jason Gunthorpe wrote:
> On Mon, Feb 10, 2020 at 11:56:08AM +0800, Jason Wang wrote:
>> +
>> +static struct vdpasim *vdpasim_create(void)
>> +{
>> +	struct vdpasim *vdpasim;
>> +	struct virtio_net_config *config;
>> +	struct vdpa_device *vdpa;
>> +	struct device *dev;
>> +	int ret = -ENOMEM;
>> +
>> +	vdpasim = kzalloc(sizeof(*vdpasim), GFP_KERNEL);
>> +	if (!vdpasim)
>> +		goto err_vdpa_alloc;
>> +
>> +	vdpasim->buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
>> +	if (!vdpasim->buffer)
>> +		goto err_buffer_alloc;
>> +
>> +	vdpasim->iommu = vhost_iotlb_alloc(2048, 0);
>> +	if (!vdpasim->iommu)
>> +		goto err_iotlb;
>> +
>> +	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);
>> +
>> +	vdpa = &vdpasim->vdpa;
>> +	vdpa->dev.release = vdpasim_release_dev;
> The driver should not provide the release function.
>
> Again the safest model is 'vdpa_alloc_device' which combines the
> kzalloc and the vdpa_init_device() and returns something that is
> error unwound with put_device()
>
> The subsystem owns the release and does the kfree and other cleanup
> like releasing the IDA.


So I think if we agree bus instead of class is used. vDPA bus can 
provide a release function in vdpa_alloc_device()?


>
>> +	vringh_set_iotlb(&vdpasim->vqs[0].vring, vdpasim->iommu);
>> +	vringh_set_iotlb(&vdpasim->vqs[1].vring, vdpasim->iommu);
>> +
>> +	dev = &vdpa->dev;
>> +	dev->coherent_dma_mask = DMA_BIT_MASK(64);
>> +	set_dma_ops(dev, &vdpasim_dma_ops);
>> +
>> +	ret = vdpa_init_device(vdpa, &vdpasim_dev->dev, dev,
>> +			       &vdpasim_net_config_ops);
>> +	if (ret)
>> +		goto err_init;
>> +
>> +	ret = vdpa_register_device(vdpa);
>> +	if (ret)
>> +		goto err_register;
> See? This error unwind is now all wrong:
>
>> +
>> +	return vdpasim;
>> +
>> +err_register:
>> +	put_device(&vdpa->dev);
> Double put_device


Yes.


>
>> +err_init:
>> +	vhost_iotlb_free(vdpasim->iommu);
>> +err_iotlb:
>> +	kfree(vdpasim->buffer);
>> +err_buffer_alloc:
>> +	kfree(vdpasim);
> kfree after vdpa_init_device() is incorrect, as the put_device now
> does kfree via release


Ok, will fix.


>
>> +static int __init vdpasim_dev_init(void)
>> +{
>> +	struct device *dev;
>> +	int ret = 0;
>> +
>> +	vdpasim_dev = kzalloc(sizeof(*vdpasim_dev), GFP_KERNEL);
>> +	if (!vdpasim_dev)
>> +		return -ENOMEM;
>> +
>> +	dev = &vdpasim_dev->dev;
>> +	dev->release = vdpasim_device_release;
>> +	dev_set_name(dev, "%s", VDPASIM_NAME);
>> +
>> +	ret = device_register(&vdpasim_dev->dev);
>> +	if (ret)
>> +		goto err_register;
>> +
>> +	if (!vdpasim_create())
>> +		goto err_register;
> Wrong error unwind here too


Will fix.

Thanks


>
>> +	return 0;
>> +
>> +err_register:
>> +	kfree(vdpasim_dev);
>> +	vdpasim_dev = NULL;
>> +	return ret;
>> +}
> Jason
>


      reply	other threads:[~2020-02-12  8:27 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-10  3:56 [PATCH V2 0/5] vDPA support Jason Wang
2020-02-10  3:56 ` [PATCH V2 1/5] vhost: factor out IOTLB Jason Wang
2020-02-10  3:56 ` [PATCH V2 2/5] vringh: IOTLB support Jason Wang
2020-02-10  3:56 ` [PATCH V2 3/5] vDPA: introduce vDPA bus Jason Wang
2020-02-11 13:47   ` Jason Gunthorpe
2020-02-12  7:55     ` Jason Wang
2020-02-12 12:51       ` Jason Gunthorpe
2020-02-13  3:34         ` Jason Wang
2020-02-13 13:41           ` Jason Gunthorpe
2020-02-13 14:58             ` Jason Wang
2020-02-13 15:05               ` Jason Gunthorpe
2020-02-13 15:05                 ` Jason Gunthorpe
2020-02-13 15:41                 ` Michael S. Tsirkin
2020-02-13 15:51                   ` Jason Gunthorpe
2020-02-13 15:56                     ` Michael S. Tsirkin
2020-02-13 15:56                       ` Michael S. Tsirkin
2020-02-13 16:24                       ` Jason Gunthorpe
2020-02-14  4:05                         ` Jason Wang
2020-02-14 14:04                           ` Jason Gunthorpe
2020-02-17  6:07                             ` Jason Wang
2020-02-17  6:07                               ` Jason Wang
2020-02-13 15:59                     ` Michael S. Tsirkin
2020-02-13 16:13                       ` Jason Gunthorpe
2020-02-14  4:39                         ` Jason Wang
2020-02-14  3:23                 ` Jason Wang
2020-02-14  3:23                   ` Jason Wang
2020-02-14 13:52                   ` Jason Gunthorpe
2020-02-17  6:08                     ` Jason Wang
2020-02-17  6:08                       ` Jason Wang
2020-02-18 13:56                       ` Jason Gunthorpe
2020-02-18 13:56                         ` Jason Gunthorpe
2020-02-19  2:59                         ` Tiwei Bie
2020-02-19  2:59                           ` Tiwei Bie
2020-02-19  5:35                         ` Jason Wang
2020-02-19  5:35                           ` Jason Wang
2020-02-19 12:53                           ` Jason Gunthorpe
2020-02-19 12:53                             ` Jason Gunthorpe
2020-02-10  3:56 ` [PATCH V2 4/5] virtio: introduce a vDPA based transport Jason Wang
2020-02-10 13:34   ` Jason Gunthorpe
2020-02-10 13:34     ` Jason Gunthorpe
2020-02-11  3:04     ` Jason Wang
2020-02-11  3:04       ` Jason Wang
2020-02-10  3:56 ` [PATCH V2 5/5] vdpasim: vDPA device simulator Jason Wang
2020-02-10 11:23   ` Michael S. Tsirkin
2020-02-11  3:12     ` Jason Wang
2020-02-11 13:52   ` Jason Gunthorpe
2020-02-12  8:27     ` Jason Wang [this message]

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=3dbadf4e-c4c5-22cc-f970-f25fa42c13d8@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.