All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Stodden <dns@arista.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	dima@arista.com, Bjorn Helgaas <helgaas@kernel.org>,
	kurt.schwemmer@microsemi.com, linux-pci@vger.kernel.org,
	logang@deltatee.com
Subject: Re: [PATCH v4 1/1] PCI: switchtec: Fix stdev_release() crash after surprise hot remove
Date: Fri, 8 Dec 2023 14:36:32 -0800	[thread overview]
Message-ID: <2C3DA10C-7AA2-4073-ABB0-320D4D280B7C@arista.com> (raw)
In-Reply-To: <89bb5f95-61b0-4e93-a542-49d6c1276f97@wanadoo.fr>



> On Dec 7, 2023, at 1:08 PM, Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:
> 
>> A PCI device hot removal may occur while stdev->cdev is held open. The call
>> to stdev_release() then happens during close or exit, at a point way past
>> switchtec_pci_remove(). Otherwise the last ref would vanish with the
>> trailing put_device(), just before return.
>> At that later point in time, the devm cleanup has already removed the
>> stdev->mmio_mrpc mapping. Also, the stdev->pdev reference was not a counted
>> one. Therefore, in DMA mode, the iowrite32() in stdev_release() will cause
>> a fatal page fault, and the subsequent dma_free_coherent(), if reached,
>> would pass a stale &stdev->pdev->dev pointer.
>> Fix by moving MRPC DMA shutdown into switchtec_pci_remove(), after
>> stdev_kill(). Counting the stdev->pdev ref is now optional, but may prevent
>> future accidents.
>> Reproducible via the script at
>> https://lore.kernel.org/r/20231113212150.96410-1-dns@arista.com
>> Link: https://lore.kernel.org/r/20231113212150.96410-2-dns@arista.com
>> Signed-off-by: Daniel Stodden <dns@arista.com>
>> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
>> Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
>> Reviewed-by: Dmitry Safonov <dima@arista.com>
> ---
> 
> ...
> 
>> @@ -1703,6 +1709,9 @@ static void switchtec_pci_remove(struct pci_dev *pdev)  >   ida_free(&switchtec_minor_ida, MINOR(stdev->dev.devt));
>> dev_info(&stdev->dev, "unregistered.\n");
>> stdev_kill(stdev);
>> + switchtec_exit_pci(stdev);  > + pci_dev_put(stdev->pdev); > + stdev->pdev = NULL; >   put_device(&stdev->dev);
>> }
> Hi,
> 
> does a similarswitchtec_exit_pci() should be called in the error handling path of switchtec_pci_probe() if an error occurs after switchtec_init_pci()?
> 

Yep, that is correct.

Looks like this is actually another regression resulting from evacuating stdev_release.
Previous code could rely on the trailing put_device(), past err_put. No more.

Cheers,
Daniel


  reply	other threads:[~2023-12-08 22:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-22  4:23 [PATCH v4 0/1] PCI: switchtec: Fix stdev_release() crash after surprise hot remove Daniel Stodden
2023-11-22  4:23 ` [PATCH v4 1/1] " Daniel Stodden
2023-11-22 15:55   ` Bjorn Helgaas
2023-11-22 19:03     ` Daniel Stodden
2023-12-07 21:08   ` Christophe JAILLET
2023-12-08 22:36     ` Daniel Stodden [this message]
2023-11-22 15:48 ` [PATCH v4 0/1] " Bjorn Helgaas

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=2C3DA10C-7AA2-4073-ABB0-320D4D280B7C@arista.com \
    --to=dns@arista.com \
    --cc=bhelgaas@google.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=dima@arista.com \
    --cc=helgaas@kernel.org \
    --cc=kurt.schwemmer@microsemi.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=logang@deltatee.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.