From: Bjorn Helgaas <helgaas@kernel.org>
To: John Garry <john.garry@huawei.com>
Cc: xuwei5@huawei.com, linuxarm@huawei.com, arm@kernel.org,
linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
joe@perches.com, linux-acpi@vger.kernel.org,
"Rafael J. Wysocki" <rjw@rjwysocki.net>
Subject: Re: [PATCH 4/5] bus: hisi_lpc: Add .remove method to avoid driver unbind crash
Date: Fri, 21 Jun 2019 08:56:19 -0500 [thread overview]
Message-ID: <20190621135619.GE82584@google.com> (raw)
In-Reply-To: <1561026716-140537-5-git-send-email-john.garry@huawei.com>
[+cc Rafael, linux-acpi]
On Thu, Jun 20, 2019 at 06:31:55PM +0800, John Garry wrote:
> The original driver author seemed to be under the impression that a driver
> cannot be removed if it does not have a .remove method. Or maybe if it is
> a built-in platform driver.
>
> This is not true. This crash can be created:
>
> root@ubuntu:/sys/bus/platform/drivers/hisi-lpc# echo HISI0191\:00 > unbind
> root@ubuntu:/sys/bus/platform/drivers/hisi-lpc# ipmitool raw 6 1
> Unable to handle kernel paging request at virtual address ffff000010035010
> ...
> The problem here is that the host goes away but the associated logical PIO
> region remains registered, as do the child devices.
>
> Fix by adding a .remove method to tidy-up by removing the child devices
> and unregistering the logical PIO region.
>
> Fixes: adf38bb0b595 ("HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings")
> Signed-off-by: John Garry <john.garry@huawei.com>
> ---
> drivers/bus/hisi_lpc.c | 34 ++++++++++++++++++++++++++++++++--
> 1 file changed, 32 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/bus/hisi_lpc.c b/drivers/bus/hisi_lpc.c
> index 6d301aafcad2..0e9f1f141c93 100644
> --- a/drivers/bus/hisi_lpc.c
> +++ b/drivers/bus/hisi_lpc.c
> @@ -456,6 +456,17 @@ struct hisi_lpc_acpi_cell {
> size_t pdata_size;
> };
>
> +static void hisi_lpc_acpi_remove(struct device *hostdev)
> +{
> + struct acpi_device *adev = ACPI_COMPANION(hostdev);
> + struct acpi_device *child;
> +
> + device_for_each_child(hostdev, NULL, hisi_lpc_acpi_remove_subdev);
> +
> + list_for_each_entry(child, &adev->children, node)
> + acpi_device_clear_enumerated(child);
There are only two other non-ACPI core callers of
acpi_device_clear_enumerated() (i2c and spi). That always makes me
wonder if we're getting too deep in ACPI internals.
> +}
> +
> /*
> * hisi_lpc_acpi_probe - probe children for ACPI FW
> * @hostdev: LPC host device pointer
> @@ -555,8 +566,7 @@ static int hisi_lpc_acpi_probe(struct device *hostdev)
> return 0;
>
> fail:
> - device_for_each_child(hostdev, NULL,
> - hisi_lpc_acpi_remove_subdev);
> + hisi_lpc_acpi_remove(hostdev);
> return ret;
> }
>
> @@ -626,6 +636,8 @@ static int hisi_lpc_probe(struct platform_device *pdev)
> return ret;
> }
>
> + dev_set_drvdata(dev, lpcdev);
> +
> io_end = lpcdev->io_host->io_start + lpcdev->io_host->size;
> dev_info(dev, "registered range [%pa - %pa]\n",
> &lpcdev->io_host->io_start, &io_end);
> @@ -633,6 +645,23 @@ static int hisi_lpc_probe(struct platform_device *pdev)
> return ret;
> }
>
> +static int hisi_lpc_remove(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct acpi_device *acpi_device = ACPI_COMPANION(dev);
> + struct hisi_lpc_dev *lpcdev = dev_get_drvdata(dev);
> + struct logic_pio_hwaddr *range = lpcdev->io_host;
> +
> + if (acpi_device)
> + hisi_lpc_acpi_remove(dev);
> + else
> + of_platform_depopulate(dev);
> +
> + logic_pio_unregister_range(range);
> +
> + return 0;
> +}
> +
> static const struct of_device_id hisi_lpc_of_match[] = {
> { .compatible = "hisilicon,hip06-lpc", },
> { .compatible = "hisilicon,hip07-lpc", },
> @@ -646,5 +675,6 @@ static struct platform_driver hisi_lpc_driver = {
> .acpi_match_table = ACPI_PTR(hisi_lpc_acpi_match),
> },
> .probe = hisi_lpc_probe,
> + .remove = hisi_lpc_remove,
> };
> builtin_platform_driver(hisi_lpc_driver);
> --
> 2.17.1
>
next prev parent reply other threads:[~2019-06-21 13:56 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-20 10:31 [PATCH 0/5] Fixes for HiSilicon LPC driver and logical PIO code John Garry
2019-06-20 10:31 ` [PATCH 1/5] lib: logic_pio: Fix RCU usage John Garry
2019-06-21 13:43 ` Bjorn Helgaas
2019-06-21 14:12 ` John Garry
2019-06-20 10:31 ` [PATCH 2/5] lib: logic_pio: Add logic_pio_unregister_range() John Garry
2019-06-21 13:49 ` Bjorn Helgaas
2019-06-21 14:19 ` John Garry
2019-06-20 10:31 ` [PATCH 3/5] bus: hisi_lpc: Unregister logical PIO range to avoid potential use-after-free John Garry
2019-06-20 10:31 ` [PATCH 4/5] bus: hisi_lpc: Add .remove method to avoid driver unbind crash John Garry
2019-06-21 13:56 ` Bjorn Helgaas [this message]
2019-06-21 14:33 ` John Garry
2019-06-20 10:31 ` [PATCH 5/5] lib: logic_pio: Enforce LOGIC_PIO_INDIRECT region ops are set at registration John Garry
2019-06-20 12:42 ` [PATCH 0/5] Fixes for HiSilicon LPC driver and logical PIO code Olof Johansson
2019-06-20 12:56 ` John Garry
2019-06-20 13:42 ` Olof Johansson
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=20190621135619.GE82584@google.com \
--to=helgaas@kernel.org \
--cc=arm@kernel.org \
--cc=joe@perches.com \
--cc=john.garry@huawei.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=rjw@rjwysocki.net \
--cc=xuwei5@huawei.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.