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, maxime.coquelin@redhat.com,
cunming.liang@intel.com, zhihong.wang@intel.com,
rob.miller@broadcom.com, xiao.w.wang@intel.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, gdawar@xilinx.com, saugatm@xilinx.com,
vmireyno@marvell.com, Bie Tiwei <tiwei.bie@intel.com>
Subject: Re: [PATCH V8 9/9] virtio: Intel IFC VF driver for VDPA
Date: Thu, 26 Mar 2020 13:50:53 +0800 [thread overview]
Message-ID: <ed04692d-236c-2eee-4429-6ef4d5d165fe@redhat.com> (raw)
In-Reply-To: <20200325123410.GX13183@mellanox.com>
On 2020/3/25 下午8:34, Jason Gunthorpe wrote:
> On Wed, Mar 25, 2020 at 04:27:11PM +0800, Jason Wang wrote:
>> +static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>> +{
>> + struct device *dev = &pdev->dev;
>> + struct ifcvf_adapter *adapter;
>> + struct ifcvf_hw *vf;
>> + int ret, i;
>> +
>> + ret = pci_enable_device(pdev);
>> + if (ret) {
>> + IFCVF_ERR(&pdev->dev, "Failed to enable device\n");
>> + goto err_enable;
>> + }
>> +
>> + ret = pci_request_regions(pdev, IFCVF_DRIVER_NAME);
>> + if (ret) {
>> + IFCVF_ERR(&pdev->dev, "Failed to request MMIO region\n");
>> + goto err_regions;
>> + }
>> +
>> + ret = pci_alloc_irq_vectors(pdev, IFCVF_MAX_INTR,
>> + IFCVF_MAX_INTR, PCI_IRQ_MSIX);
>> + if (ret < 0) {
>> + IFCVF_ERR(&pdev->dev, "Failed to alloc irq vectors\n");
>> + goto err_vectors;
>> + }
>> +
>> + adapter = vdpa_alloc_device(ifcvf_adapter, vdpa, dev, &ifc_vdpa_ops);
>> + if (adapter == NULL) {
>> + IFCVF_ERR(&pdev->dev, "Failed to allocate vDPA structure");
>> + ret = -ENOMEM;
>> + goto err_alloc;
>> + }
>> +
>> + adapter->dev = dev;
>> + pci_set_master(pdev);
>> + pci_set_drvdata(pdev, adapter);
>> +
>> + ret = ifcvf_request_irq(adapter);
>> + if (ret) {
>> + IFCVF_ERR(&pdev->dev, "Failed to request MSI-X irq\n");
>> + goto err_msix;
>> + }
>> +
>> + vf = &adapter->vf;
>> + for (i = 0; i < IFCVF_PCI_MAX_RESOURCE; i++) {
>> + vf->mem_resource[i].phys_addr = pci_resource_start(pdev, i);
>> + vf->mem_resource[i].len = pci_resource_len(pdev, i);
>> + if (!vf->mem_resource[i].len)
>> + continue;
>> +
>> + vf->mem_resource[i].addr = pci_iomap_range(pdev, i, 0,
>> + vf->mem_resource[i].len);
>> + if (!vf->mem_resource[i].addr) {
>> + IFCVF_ERR(&pdev->dev,
>> + "Failed to map IO resource %d\n", i);
>> + ret = -EINVAL;
>> + goto err_msix;
>> + }
>> + }
>> +
>> + if (ifcvf_init_hw(vf, pdev) < 0) {
>> + ret = -EINVAL;
>> + goto err_msix;
>> + }
>> +
>> + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
>> + if (ret)
>> + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
>> +
>> + if (ret) {
>> + IFCVF_ERR(adapter->dev, "No usable DMA confiugration\n");
>> + ret = -EINVAL;
>> + goto err_msix;
>> + }
>> +
>> + adapter->vdpa.dma_dev = dev;
>> + ret = vdpa_register_device(&adapter->vdpa);
>> + if (ret) {
>> + IFCVF_ERR(adapter->dev, "Failed to register ifcvf to vdpa bus");
>> + goto err_msix;
>> + }
>> +
>> + return 0;
>> +
>> +err_msix:
>> + put_device(&adapter->vdpa.dev);
>> + return ret;
>> +err_alloc:
>> + pci_free_irq_vectors(pdev);
>> +err_vectors:
>> + pci_release_regions(pdev);
>> +err_regions:
>> + pci_disable_device(pdev);
>> +err_enable:
>> + return ret;
>> +}
> I personally don't like seeing goto unwinds with multiple returns, and
> here I think it is actually a tiny bug.
>
> All touches to the PCI device must stop before the driver core
> remove() returns - so these pci function cannot be in the kref put
> release function anyhow.
I'm not sure I get here. IFCVF held refcnt of its PCI parent, so it
looks to me it's safe to free PCI resources in vDPA free callback?
>
> Suggest to use the devm versions of the above instead, and then you
> can reorder things so the allocation is done first.
>
> Jason
Using devm looks nice, but if it's possible I prefer to tweak on top.
Thanks
>
next prev parent reply other threads:[~2020-03-26 5:51 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-25 8:27 [PATCH V8 0/9] vDPA support Jason Wang
2020-03-25 8:27 ` [PATCH V8 1/9] vhost: refine vhost and vringh kconfig Jason Wang
2020-03-25 8:27 ` [PATCH V8 2/9] vhost: allow per device message handler Jason Wang
2020-03-25 8:27 ` [PATCH V8 3/9] vhost: factor out IOTLB Jason Wang
2020-03-25 8:27 ` [PATCH V8 4/9] vringh: IOTLB support Jason Wang
2020-03-25 8:27 ` [PATCH V8 5/9] vDPA: introduce vDPA bus Jason Wang
2020-03-25 12:29 ` Jason Gunthorpe
2020-03-26 5:51 ` Jason Wang
2020-03-25 8:27 ` [PATCH V8 6/9] virtio: introduce a vDPA based transport Jason Wang
2020-03-25 8:27 ` [PATCH V8 7/9] vhost: introduce vDPA-based backend Jason Wang
2020-03-25 8:27 ` [PATCH V8 8/9] vdpasim: vDPA device simulator Jason Wang
2020-03-25 8:27 ` [PATCH V8 9/9] virtio: Intel IFC VF driver for VDPA Jason Wang
2020-03-25 12:34 ` Jason Gunthorpe
2020-03-26 5:50 ` Jason Wang [this message]
2020-03-26 12:17 ` Jason Gunthorpe
2020-03-26 13:56 ` 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=ed04692d-236c-2eee-4429-6ef4d5d165fe@redhat.com \
--to=jasowang@redhat.com \
--cc=aadam@redhat.com \
--cc=cunming.liang@intel.com \
--cc=eperezma@redhat.com \
--cc=gdawar@xilinx.com \
--cc=hanand@xilinx.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=saugatm@xilinx.com \
--cc=shahafs@mellanox.com \
--cc=stefanha@redhat.com \
--cc=tiwei.bie@intel.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=vmireyno@marvell.com \
--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).