From: Dan Carpenter <dan.carpenter@linaro.org>
To: Shijith Thotton <sthotton@marvell.com>
Cc: virtualization@lists.linux.dev, mst@redhat.com,
jasowang@redhat.com, schalla@marvell.com, vattunuru@marvell.com,
ndabilpuram@marvell.com, jerinj@marvell.com,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Satha Rao" <skoteshwar@marvell.com>,
"open list" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/4] vdpa/octeon_ep: enable support for multiple interrupts per device
Date: Wed, 20 Nov 2024 11:05:02 +0300 [thread overview]
Message-ID: <b799bf24-876a-41da-b297-d2323c314674@stanley.mountain> (raw)
In-Reply-To: <20241120070508.789508-1-sthotton@marvell.com>
On Wed, Nov 20, 2024 at 12:34:50PM +0530, Shijith Thotton wrote:
> @@ -63,44 +80,53 @@ static irqreturn_t octep_vdpa_intr_handler(int irq, void *data)
> static void octep_free_irqs(struct octep_hw *oct_hw)
> {
> struct pci_dev *pdev = oct_hw->pdev;
> + int irq;
> +
> + for (irq = 0; irq < oct_hw->nb_irqs && oct_hw->irqs; irq++) {
> + if (oct_hw->irqs[irq] < 0)
> + continue;
>
> - if (oct_hw->irq != -1) {
> - devm_free_irq(&pdev->dev, oct_hw->irq, oct_hw);
> - oct_hw->irq = -1;
> + devm_free_irq(&pdev->dev, oct_hw->irqs[irq], oct_hw);
> }
> +
> pci_free_irq_vectors(pdev);
> + kfree(oct_hw->irqs);
You should add:
oct_hw->nb_irqs = 0;
oct_hw->irqs = NULL;
Otherwise if reset is called twice in a row, before re-initializing the IRQs it
results in a use after free.
> }
>
> static int octep_request_irqs(struct octep_hw *oct_hw)
> {
> struct pci_dev *pdev = oct_hw->pdev;
> - int ret, irq;
> + int ret, irq, idx;
>
> - /* Currently HW device provisions one IRQ per VF, hence
> - * allocate one IRQ for all virtqueues call interface.
> - */
> - ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSIX);
> + ret = pci_alloc_irq_vectors(pdev, 1, oct_hw->nb_irqs, PCI_IRQ_MSIX);
> if (ret < 0) {
> dev_err(&pdev->dev, "Failed to alloc msix vector");
> return ret;
> }
>
> - snprintf(oct_hw->vqs->msix_name, sizeof(oct_hw->vqs->msix_name),
> - OCTEP_VDPA_DRIVER_NAME "-vf-%d", pci_iov_vf_id(pdev));
> + oct_hw->irqs = kcalloc(oct_hw->nb_irqs, sizeof(int), GFP_KERNEL);
This isn't free on the ->release() path or whatever. octep_free_irqs() is
called on reset() but we rely on devm_ to free the IRQs on ->release(). Use
devm_kcalloc() here as well, probably.
> + if (!oct_hw->irqs) {
> + ret = -ENOMEM;
> + goto free_irqs;
> + }
>
> - irq = pci_irq_vector(pdev, 0);
> - ret = devm_request_irq(&pdev->dev, irq, octep_vdpa_intr_handler, 0,
> - oct_hw->vqs->msix_name, oct_hw);
> - if (ret) {
> - dev_err(&pdev->dev, "Failed to register interrupt handler\n");
> - goto free_irq_vec;
> + memset(oct_hw->irqs, -1, sizeof(oct_hw->irqs));
This works, but it would be more normal to just leave it zeroed and check for
zero instead of checking for negatives. There is never a zero IRQ. See my blog
for more details:
https://staticthinking.wordpress.com/2023/08/07/writing-a-check-for-zero-irq-error-codes/
regards,
dan carpenter
> +
> + for (idx = 0; idx < oct_hw->nb_irqs; idx++) {
> + irq = pci_irq_vector(pdev, idx);
> + ret = devm_request_irq(&pdev->dev, irq, octep_vdpa_intr_handler, 0,
> + dev_name(&pdev->dev), oct_hw);
> + if (ret) {
> + dev_err(&pdev->dev, "Failed to register interrupt handler\n");
> + goto free_irqs;
> + }
> + oct_hw->irqs[idx] = irq;
> }
> - oct_hw->irq = irq;
>
> return 0;
>
> -free_irq_vec:
> - pci_free_irq_vectors(pdev);
> +free_irqs:
> + octep_free_irqs(oct_hw);
> return ret;
> }
>
regards,
dan carpenter
prev parent reply other threads:[~2024-11-20 8:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-20 7:04 [PATCH 1/4] vdpa/octeon_ep: enable support for multiple interrupts per device Shijith Thotton
2024-11-20 7:04 ` [PATCH 2/4] vdpa/octeon_ep: handle device config change events Shijith Thotton
2024-11-20 7:26 ` Dan Carpenter
2024-11-20 7:04 ` [PATCH 3/4] vdpa/octeon_ep: read vendor-specific PCI capability Shijith Thotton
2024-11-20 7:04 ` [PATCH 4/4] vdpa/octeon_ep: add interrupt handler for virtio crypto device Shijith Thotton
2024-11-20 8:05 ` Dan Carpenter [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=b799bf24-876a-41da-b297-d2323c314674@stanley.mountain \
--to=dan.carpenter@linaro.org \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=jerinj@marvell.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=ndabilpuram@marvell.com \
--cc=schalla@marvell.com \
--cc=skoteshwar@marvell.com \
--cc=sthotton@marvell.com \
--cc=vattunuru@marvell.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.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