From: Bjorn Helgaas <helgaas@kernel.org>
To: John Garry <john.garry@huawei.com>
Cc: Thierry Reding <thierry.reding@gmail.com>,
mika.westerberg@linux.intel.com, rafael@kernel.org,
lorenzo.pieralisi@arm.com, rjw@rjwysocki.net,
hanjun.guo@linaro.org, robh+dt@kernel.org, bhelgaas@google.com,
arnd@arndb.de, mark.rutland@arm.com, olof@lixom.net,
dann.frazier@canonical.com, andy.shevchenko@gmail.com,
robh@kernel.org, andriy.shevchenko@linux.intel.com,
joe@perches.com, benh@kernel.crashing.org,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-acpi@vger.kernel.org, linuxarm@huawei.com, minyard@acm.org,
devicetree@vger.kernel.org, linux-arch@vger.kernel.org,
rdunlap@infradead.org, gregkh@linuxfoundation.org,
akpm@linux-foundation.org, frowand.list@gmail.com, agraf@suse.de,
linux-tegra@vger.kernel.org
Subject: Re: [PATCH v17 01/10] LIB: Introduce a generic PIO mapping method
Date: Tue, 3 Apr 2018 12:53:11 -0500 [thread overview]
Message-ID: <20180403175311.GD60020@bhelgaas-glaptop.roam.corp.google.com> (raw)
In-Reply-To: <19c46196-304a-1574-89c9-01c71d123539@huawei.com>
On Tue, Apr 03, 2018 at 06:02:43PM +0100, John Garry wrote:
> On 03/04/2018 17:37, Thierry Reding wrote:
> > On Tue, Apr 03, 2018 at 05:01:37PM +0100, John Garry wrote:
> > > > > > +int logic_pio_register_range(struct logic_pio_hwaddr *new_range)
> > > > > > +{
> > > > > > + struct logic_pio_hwaddr *range;
> > > > > > + resource_size_t start = new_range->hw_start;
> > > > > > + resource_size_t end = new_range->hw_start + new_range->size;
> > > > > > + resource_size_t mmio_sz = 0;
> > > > > > + resource_size_t iio_sz = MMIO_UPPER_LIMIT;
> > > > > > + int ret = 0;
> > > > > > +
> > > > > > + if (!new_range || !new_range->fwnode || !new_range->size)
> > > > > > + return -EINVAL;
> > > > > > +
> > > > > > + mutex_lock(&io_range_mutex);
> > > > > > + list_for_each_entry_rcu(range, &io_range_list, list) {
> > > > > > + if (range->fwnode == new_range->fwnode) {
> > > > > > + /* range already there */
> > > > > > + ret = -EFAULT;
> > > > > > + goto end_register;
> > > > > > + }
> > > > >
> > >
> > > Hi Thierry,
> > >
> > > > > This is the -EFAULT that propagates to pci-tegra.c's ->probe() and fails
> > > > > to bind the driver.
> > > > >
> > > > > I'm not exactly sure what's causing the duplicate here because it's
> > > > > rather difficult to get at something useful from just the ->fwnode, but
> > > > > I'm fairly sure that the reason this breaks is because the Tegra driver
> > > > > will defer probe due to some regulators that aren't available on the
> > > > > first try. Given the above code and the rest of this file, I can't see a
> > > > > way to "fix" the driver and remove the I/O range on failure.
> > > > >
> > > > > This is doubly bad because this doesn't only leak the ranges on probe
> > > > > deferral, but also on driver unload, and we just added support for
> > > > > building the Tegra driver as a loadable module, so these are actually
> > > > > cases that can happen in regular uses of the driver.
> > > > >
> > > > > I have no idea on how to fix this. Anyone know of a quick fix to restore
> > > > > PCI for Tegra other than reverting all of these changes?
> > > > >
> > > > > I suppose an API could be added to unregister the range, but the calling
> > > > > sequence is rather obfuscated, so removing the range will look totally
> > > > > asymmetric, I'm afraid.
> > > > >
> > > > > Here's the call stack:
> > > > >
> > > > > tegra_pcie_probe()
> > > > > tegra_pcie_parse_dt()
> > > > > of_pci_range_to_resource()
> > > > > pci_register_io_range()
> > > > > logic_pio_register_range()
> > > > >
> > > > > So the range here is registered as part of a resource parsing function,
> > > > > which is supposed to not have any side-effects. There's no equivalent of
> > > > > that parsing routine (i.e. no "unparse" function that would undo the
> > > > > effects of parsing).
> > > > >
> > > > > Perhaps a cleaner way would be to decouple the parsing from the actual
> > > > > request step that has the side-effect.
> > >
> > > This could be added if we agreed that it would be useful.
> >
> > I guess in most cases these ranges will be static at least during one
> > boot. But it still feels like this should be removed when the driver
> > goes away. While this may not depend on data by the driver, and hence
> > won't cause a crash or anything, it just seems wrong to leave it
> > around when the driver no longer isn't.
>
> That sounds reasonable, considering we do unmap the iospace when we release
> - so it looks like currently we're leaving some IO range reserved which does
> not have a mapping.
>
> However this change seems non-trivial, considering we're now even coupling
> the PIO range registration into DT parsing.
>
> >
> > > > > Going back in history a little, it looks like even before this commit
> > > > > the I/O range registration was triggered by the parsing code and even
> > > > > the range leak was there, except that it caused pci_register_io_range()
> > > > > to return 0 rather than -EFAULT. Perhaps the quickest fix for this would
> > > > > be to do the same in the new code and restore drivers that accidentally
> > > > > depend on this behaviour.
> > > >
> > > > I can confirm that the following fixes the issue for me, though I don't
> > > > think it's a very clean fix given that the range will remain requested
> > > > forever, even if the driver is gone. But since that's already been the
> > > > case for quite a while, probably something that can be fixed separately.
> > > >
> > >
> > > Right, there was no way to deregister the range previously. From looking at
> > > the history here I see no reason to not support it.
> > >
> > > As for this patch, as you said, the only difference is that we fault on
> > > trying to register the same range again. So this solution seems reasonable.
> >
> > Okay, I can turn this into a proper patch to fix this up. I suspect that
> > other drivers may be subject to the same regression. For the longer term
> > I think it'd be better to properly undo the registration on failure and
> > removal, but I suspect that it'd be quite a bit of work and not suitable
> > for v4.17 anymore.
>
> Thanks, I had started to put the patch together but if you're happy to
> continue then that's fine. Please let me know.
Since you seem to agree this is the right short-term fix and I would
squash it into the original commit anyway, I went ahead and did that
so we could get this into linux-next as soon as possible.
Here's the diff from my previous "next" branch with respect to this
series:
diff --git a/lib/logic_pio.c b/lib/logic_pio.c
index 29cedeadb397..4664b87e1c5f 100644
--- a/lib/logic_pio.c
+++ b/lib/logic_pio.c
@@ -46,7 +46,6 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range)
list_for_each_entry_rcu(range, &io_range_list, list) {
if (range->fwnode == new_range->fwnode) {
/* range already there */
- ret = -EFAULT;
goto end_register;
}
if (range->flags == LOGIC_PIO_CPU_MMIO &&
next prev parent reply other threads:[~2018-04-03 17:53 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-14 18:15 [PATCH v17 00/10] LPC: legacy ISA I/O support John Garry
2018-03-14 18:15 ` [PATCH v17 01/10] LIB: Introduce a generic PIO mapping method John Garry
2018-04-03 14:04 ` Thierry Reding
2018-04-03 14:39 ` Thierry Reding
2018-04-03 16:01 ` John Garry
2018-04-03 16:37 ` Thierry Reding
2018-04-03 17:02 ` John Garry
2018-04-03 17:53 ` Bjorn Helgaas [this message]
2018-04-03 18:24 ` John Garry
2018-03-14 18:15 ` [PATCH v17 02/10] PCI: Remove unused __weak attribute in pci_register_io_range() John Garry
2018-03-14 18:15 ` [PATCH v17 03/10] PCI: Add fwnode handler as input param of pci_register_io_range() John Garry
2018-03-14 18:15 ` [PATCH v17 04/10] PCI: Apply the new generic I/O management on PCI IO hosts John Garry
2018-04-03 13:45 ` Thierry Reding
2018-04-03 14:02 ` John Garry
2018-03-14 18:15 ` [PATCH v17 05/10] OF: Add missing I/O range exception for indirect-IO devices John Garry
2018-03-14 18:15 ` [PATCH v17 06/10] HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings John Garry
2018-03-14 18:15 ` [PATCH v17 07/10] ACPI / scan: rename acpi_is_serial_bus_slave() to widen use John Garry
2018-03-19 10:27 ` Rafael J. Wysocki
2018-03-14 18:15 ` [PATCH v17 08/10] ACPI / scan: do not enumerate Indirect IO host children John Garry
2018-03-19 10:30 ` Rafael J. Wysocki
2018-03-19 10:48 ` John Garry
2018-03-19 10:57 ` Rafael J. Wysocki
2018-03-19 11:13 ` John Garry
2018-03-14 18:15 ` [PATCH v17 09/10] HISI LPC: Add ACPI support John Garry
2018-03-14 18:15 ` [PATCH v17 10/10] MAINTAINERS: Add maintainer for HiSilicon LPC driver John Garry
2018-03-21 23:39 ` [PATCH v17 00/10] LPC: legacy ISA I/O support Bjorn Helgaas
2018-03-22 10:38 ` John Garry
2018-03-22 13:35 ` Bjorn Helgaas
2018-03-22 14:18 ` John Garry
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=20180403175311.GD60020@bhelgaas-glaptop.roam.corp.google.com \
--to=helgaas@kernel.org \
--cc=agraf@suse.de \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=andy.shevchenko@gmail.com \
--cc=arnd@arndb.de \
--cc=benh@kernel.crashing.org \
--cc=bhelgaas@google.com \
--cc=dann.frazier@canonical.com \
--cc=devicetree@vger.kernel.org \
--cc=frowand.list@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=hanjun.guo@linaro.org \
--cc=joe@perches.com \
--cc=john.garry@huawei.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=lorenzo.pieralisi@arm.com \
--cc=mark.rutland@arm.com \
--cc=mika.westerberg@linux.intel.com \
--cc=minyard@acm.org \
--cc=olof@lixom.net \
--cc=rafael@kernel.org \
--cc=rdunlap@infradead.org \
--cc=rjw@rjwysocki.net \
--cc=robh+dt@kernel.org \
--cc=robh@kernel.org \
--cc=thierry.reding@gmail.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