diff mbox

[v2,2/3] drivers: pci: host-generic: claim bus resources on PCI_PROBE_ONLY set-ups

Message ID 1456843449-19393-3-git-send-email-lorenzo.pieralisi@arm.com (mailing list archive)
State New, archived
Delegated to: Bjorn Helgaas
Headers show

Commit Message

Lorenzo Pieralisi March 1, 2016, 2:44 p.m. UTC
The PCI host generic driver does not reassign bus resources on systems
that require the BARs set-up to be immutable (ie PCI_PROBE_ONLY) since
that would trigger system failures. Nonetheless, PCI bus resources
allocated to PCI bridge and devices must be claimed in order to be
validated and inserted in the kernel resource tree, but the current
driver omits the resources claiming and relies on arch specific kludges
to prevent probing failure (ie preventing resources enablement on
PCI_PROBE_ONLY systems).

This patch adds code to the PCI host generic driver that correctly
claims bus resources upon probe on systems that are required to
prevent reassignment after bus enumeration, so that the allocated
resources can be enabled successfully upon PCI device drivers probing,
without resorting to arch back-ends workarounds.

Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Will Deacon <will.deacon@arm.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: David Daney <david.daney@cavium.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
---
 drivers/pci/host/pci-host-generic.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Bjorn Helgaas April 12, 2016, 4:43 a.m. UTC | #1
Hi Lorenzo,

On Tue, Mar 01, 2016 at 02:44:08PM +0000, Lorenzo Pieralisi wrote:
> The PCI host generic driver does not reassign bus resources on systems
> that require the BARs set-up to be immutable (ie PCI_PROBE_ONLY) since
> that would trigger system failures. Nonetheless, PCI bus resources
> allocated to PCI bridge and devices must be claimed in order to be
> validated and inserted in the kernel resource tree, but the current
> driver omits the resources claiming and relies on arch specific kludges
> to prevent probing failure (ie preventing resources enablement on
> PCI_PROBE_ONLY systems).
> 
> This patch adds code to the PCI host generic driver that correctly
> claims bus resources upon probe on systems that are required to
> prevent reassignment after bus enumeration, so that the allocated
> resources can be enabled successfully upon PCI device drivers probing,
> without resorting to arch back-ends workarounds.
> 
> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Acked-by: Will Deacon <will.deacon@arm.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: David Daney <david.daney@cavium.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> ---
>  drivers/pci/host/pci-host-generic.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/host/pci-host-generic.c b/drivers/pci/host/pci-host-generic.c
> index 1652bc7..e529825 100644
> --- a/drivers/pci/host/pci-host-generic.c
> +++ b/drivers/pci/host/pci-host-generic.c
> @@ -252,7 +252,10 @@ static int gen_pci_probe(struct platform_device *pdev)
>  
>  	pci_fixup_irqs(pci_common_swizzle, of_irq_parse_and_map_pci);
>  
> -	if (!pci_has_flag(PCI_PROBE_ONLY)) {
> +
> +	if (pci_has_flag(PCI_PROBE_ONLY)) {
> +		pci_bus_claim_resources(bus);
> +	} else {
>  		pci_bus_size_bridges(bus);
>  		pci_bus_assign_resources(bus);
>  

The next patch removes the arm and arm64 pcibios_enable_device()
implementations, which implies that arm and arm64 only need the generic
version, which simply calls pci_enable_resources().  That assumes r->parent
is set.

After this patch, we'll call pci_bus_claim_resources() for the
PCI_PROBE_ONLY case, and that sets r->parent for all the resources.

Where does r->parent get set in the non-PCI_PROBE_ONLY case?  Obviously
that path *works*, because you're not changing anything there.  I'd just
like to have a hint that makes this change more obvious.

Bjorn
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Lorenzo Pieralisi April 12, 2016, 3:48 p.m. UTC | #2
On Mon, Apr 11, 2016 at 11:43:11PM -0500, Bjorn Helgaas wrote:
> Hi Lorenzo,
> 
> On Tue, Mar 01, 2016 at 02:44:08PM +0000, Lorenzo Pieralisi wrote:
> > The PCI host generic driver does not reassign bus resources on systems
> > that require the BARs set-up to be immutable (ie PCI_PROBE_ONLY) since
> > that would trigger system failures. Nonetheless, PCI bus resources
> > allocated to PCI bridge and devices must be claimed in order to be
> > validated and inserted in the kernel resource tree, but the current
> > driver omits the resources claiming and relies on arch specific kludges
> > to prevent probing failure (ie preventing resources enablement on
> > PCI_PROBE_ONLY systems).
> > 
> > This patch adds code to the PCI host generic driver that correctly
> > claims bus resources upon probe on systems that are required to
> > prevent reassignment after bus enumeration, so that the allocated
> > resources can be enabled successfully upon PCI device drivers probing,
> > without resorting to arch back-ends workarounds.
> > 
> > Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> > Acked-by: Will Deacon <will.deacon@arm.com>
> > Cc: Arnd Bergmann <arnd@arndb.de>
> > Cc: David Daney <david.daney@cavium.com>
> > Cc: Will Deacon <will.deacon@arm.com>
> > Cc: Bjorn Helgaas <bhelgaas@google.com>
> > ---
> >  drivers/pci/host/pci-host-generic.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/pci/host/pci-host-generic.c b/drivers/pci/host/pci-host-generic.c
> > index 1652bc7..e529825 100644
> > --- a/drivers/pci/host/pci-host-generic.c
> > +++ b/drivers/pci/host/pci-host-generic.c
> > @@ -252,7 +252,10 @@ static int gen_pci_probe(struct platform_device *pdev)
> >  
> >  	pci_fixup_irqs(pci_common_swizzle, of_irq_parse_and_map_pci);
> >  
> > -	if (!pci_has_flag(PCI_PROBE_ONLY)) {
> > +
> > +	if (pci_has_flag(PCI_PROBE_ONLY)) {
> > +		pci_bus_claim_resources(bus);
> > +	} else {
> >  		pci_bus_size_bridges(bus);
> >  		pci_bus_assign_resources(bus);
> >  
> 
> The next patch removes the arm and arm64 pcibios_enable_device()
> implementations, which implies that arm and arm64 only need the generic
> version, which simply calls pci_enable_resources().  That assumes r->parent
> is set.
> 
> After this patch, we'll call pci_bus_claim_resources() for the
> PCI_PROBE_ONLY case, and that sets r->parent for all the resources.
> 
> Where does r->parent get set in the non-PCI_PROBE_ONLY case?  Obviously
> that path *works*, because you're not changing anything there.  I'd just
> like to have a hint that makes this change more obvious.

On all ARM/ARM64 PCI controllers drivers I am aware of (apart from the
kvmtool PCI host controller which does require PCI_PROBE_ONLY, so we need
this patch), resources are always reassigned and the core code reassigning
them takes care of assigning their parent pointers too, to answer your
question.

As for this patch series, given that:

commit (in -next) 903589ca7165 ("ARM: 8554/1: kernel: pci: remove
pci=firmware command line parameter handling") removes the PCI_PROBE_ONLY
handling from the (ARM) command line, the PCI host generic becomes the
last ARM/ARM64 host controller that requires PCI_PROBE_ONLY to function
(depending on DT settings).

The idea behind adding pci_bus_claim_resources (patch 1) to core code
was that it could be reused by other arches too, I do not have evidence
though, I have to prove it, so I'd rather squash patch 1 into this one
and make the code claiming resources local to the PCI host generic,
I can't add a generic PCI core API just for one host controller
(IMHO we should add an API that allows us to claim bus resources and
realloc the ones for which claiming fail - which may mean releasing
bridges resources and realloc/resize them - code is in the kernel already
I have to write that API).

The code claiming resources on x86, IA64 and PowerPC looks extremely
similar but it has to be proven that a generic function has a chance
to work, so patch 1 is not really justified at present.

If you have no objections I will squash patch 1 into this one (moving
the respective code in PCI host generic driver), and I would not merge
this series till the commit above in -next gets in the kernel (which
makes sure that PCI_PROBE_ONLY can't be set on the command line, that's
fundamental to this series, at least on ARM, on ARM64 DT is the only way
PCI_PROBE_ONLY can be set and only on host controllers that check the
chosen node property - ie PCI host generic, that we are patching).

Thanks,
Lorenzo
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bjorn Helgaas April 15, 2016, 1:08 p.m. UTC | #3
On Tue, Apr 12, 2016 at 04:48:10PM +0100, Lorenzo Pieralisi wrote:
> On Mon, Apr 11, 2016 at 11:43:11PM -0500, Bjorn Helgaas wrote:
> > Hi Lorenzo,
> > 
> > On Tue, Mar 01, 2016 at 02:44:08PM +0000, Lorenzo Pieralisi wrote:
> > > The PCI host generic driver does not reassign bus resources on systems
> > > that require the BARs set-up to be immutable (ie PCI_PROBE_ONLY) since
> > > that would trigger system failures. Nonetheless, PCI bus resources
> > > allocated to PCI bridge and devices must be claimed in order to be
> > > validated and inserted in the kernel resource tree, but the current
> > > driver omits the resources claiming and relies on arch specific kludges
> > > to prevent probing failure (ie preventing resources enablement on
> > > PCI_PROBE_ONLY systems).
> > > 
> > > This patch adds code to the PCI host generic driver that correctly
> > > claims bus resources upon probe on systems that are required to
> > > prevent reassignment after bus enumeration, so that the allocated
> > > resources can be enabled successfully upon PCI device drivers probing,
> > > without resorting to arch back-ends workarounds.
> > > 
> > > Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> > > Acked-by: Will Deacon <will.deacon@arm.com>
> > > Cc: Arnd Bergmann <arnd@arndb.de>
> > > Cc: David Daney <david.daney@cavium.com>
> > > Cc: Will Deacon <will.deacon@arm.com>
> > > Cc: Bjorn Helgaas <bhelgaas@google.com>
> > > ---
> > >  drivers/pci/host/pci-host-generic.c | 5 ++++-
> > >  1 file changed, 4 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/pci/host/pci-host-generic.c b/drivers/pci/host/pci-host-generic.c
> > > index 1652bc7..e529825 100644
> > > --- a/drivers/pci/host/pci-host-generic.c
> > > +++ b/drivers/pci/host/pci-host-generic.c
> > > @@ -252,7 +252,10 @@ static int gen_pci_probe(struct platform_device *pdev)
> > >  
> > >  	pci_fixup_irqs(pci_common_swizzle, of_irq_parse_and_map_pci);
> > >  
> > > -	if (!pci_has_flag(PCI_PROBE_ONLY)) {
> > > +
> > > +	if (pci_has_flag(PCI_PROBE_ONLY)) {
> > > +		pci_bus_claim_resources(bus);
> > > +	} else {
> > >  		pci_bus_size_bridges(bus);
> > >  		pci_bus_assign_resources(bus);
> > >  
> > 
> > The next patch removes the arm and arm64 pcibios_enable_device()
> > implementations, which implies that arm and arm64 only need the generic
> > version, which simply calls pci_enable_resources().  That assumes r->parent
> > is set.
> > 
> > After this patch, we'll call pci_bus_claim_resources() for the
> > PCI_PROBE_ONLY case, and that sets r->parent for all the resources.
> > 
> > Where does r->parent get set in the non-PCI_PROBE_ONLY case?  Obviously
> > that path *works*, because you're not changing anything there.  I'd just
> > like to have a hint that makes this change more obvious.
> 
> On all ARM/ARM64 PCI controllers drivers I am aware of (apart from the
> kvmtool PCI host controller which does require PCI_PROBE_ONLY, so we need
> this patch), resources are always reassigned and the core code reassigning
> them takes care of assigning their parent pointers too, to answer your
> question.

Here's what I find confusing.  Consider these three cases:

  1) Firmware programs no BARs and we reassign everything.  We call
  pci_bus_assign_resources(), and the pci_assign_resource() ...
  allocate_resource() path makes sure everything is claimed.  This is
  apparently the normal arm/arm64 path, and it already works.

  2) Firmware programs all BARs and we set PCI_PROBE_ONLY.  After this
  series, we'll claim the resources and remove the PCI_PROBE_ONLY
  special case in pcibios_enable_device().  This is great!

  3) Firmware programs all BARs but we don't set PCI_PROBE_ONLY.  We
  call pci_bus_assign_resources(), but I think it does nothing because
  everything is already assigned.  The resources are not claimed and
  pci_enable_resources() will fail.

This last case 3) is the problem.  I'm guessing this case doesn't
currently occur on arm/arm64, but it's the normal case on x86, and it
seems perverse that things work if firmware does nothing, but they
don't work if firmware does more setup.

So I think we should add some sort of arm/arm64-specific
pci_claim_resource() path similar to the pcibios_allocate_resources()
stuff on x86.

> As for this patch series, given that:
> 
> commit (in -next) 903589ca7165 ("ARM: 8554/1: kernel: pci: remove
> pci=firmware command line parameter handling") removes the PCI_PROBE_ONLY
> handling from the (ARM) command line, the PCI host generic becomes the
> last ARM/ARM64 host controller that requires PCI_PROBE_ONLY to function
> (depending on DT settings).
> 
> The idea behind adding pci_bus_claim_resources (patch 1) to core code
> was that it could be reused by other arches too, I do not have evidence
> though, I have to prove it, so I'd rather squash patch 1 into this one
> and make the code claiming resources local to the PCI host generic,
> I can't add a generic PCI core API just for one host controller
> (IMHO we should add an API that allows us to claim bus resources and
> realloc the ones for which claiming fail - which may mean releasing
> bridges resources and realloc/resize them - code is in the kernel already
> I have to write that API).
> 
> The code claiming resources on x86, IA64 and PowerPC looks extremely
> similar but it has to be proven that a generic function has a chance
> to work, so patch 1 is not really justified at present.

I don't really object to patch 1, but you're right that it's possible
we could do a better job later.  I would certainly like to get that
sort of code (including the pcibios_allocate_resources() stuff I just
mentioned) out of the arches and into the core somehow.

> If you have no objections I will squash patch 1 into this one (moving
> the respective code in PCI host generic driver), and I would not merge
> this series till the commit above in -next gets in the kernel (which
> makes sure that PCI_PROBE_ONLY can't be set on the command line, that's
> fundamental to this series, at least on ARM, on ARM64 DT is the only way
> PCI_PROBE_ONLY can be set and only on host controllers that check the
> chosen node property - ie PCI host generic, that we are patching).

If there's a stable branch containing 903589ca7165 ("ARM: 8554/1:
kernel: pci: remove pci=firmware command line parameter handling"), I
can pull that and merge your series on top of it.

Bjorn
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Lorenzo Pieralisi April 18, 2016, 10:01 a.m. UTC | #4
On Fri, Apr 15, 2016 at 08:08:03AM -0500, Bjorn Helgaas wrote:
> On Tue, Apr 12, 2016 at 04:48:10PM +0100, Lorenzo Pieralisi wrote:

[...]

> > > The next patch removes the arm and arm64 pcibios_enable_device()
> > > implementations, which implies that arm and arm64 only need the generic
> > > version, which simply calls pci_enable_resources().  That assumes r->parent
> > > is set.
> > > 
> > > After this patch, we'll call pci_bus_claim_resources() for the
> > > PCI_PROBE_ONLY case, and that sets r->parent for all the resources.
> > > 
> > > Where does r->parent get set in the non-PCI_PROBE_ONLY case?  Obviously
> > > that path *works*, because you're not changing anything there.  I'd just
> > > like to have a hint that makes this change more obvious.
> > 
> > On all ARM/ARM64 PCI controllers drivers I am aware of (apart from the
> > kvmtool PCI host controller which does require PCI_PROBE_ONLY, so we need
> > this patch), resources are always reassigned and the core code reassigning
> > them takes care of assigning their parent pointers too, to answer your
> > question.
> 
> Here's what I find confusing.  Consider these three cases:
> 
>   1) Firmware programs no BARs and we reassign everything.  We call
>   pci_bus_assign_resources(), and the pci_assign_resource() ...
>   allocate_resource() path makes sure everything is claimed.  This is
>   apparently the normal arm/arm64 path, and it already works.
> 
>   2) Firmware programs all BARs and we set PCI_PROBE_ONLY.  After this
>   series, we'll claim the resources and remove the PCI_PROBE_ONLY
>   special case in pcibios_enable_device().  This is great!
> 
>   3) Firmware programs all BARs but we don't set PCI_PROBE_ONLY.  We
>   call pci_bus_assign_resources(), but I think it does nothing because
>   everything is already assigned.  The resources are not claimed and
>   pci_enable_resources() will fail.

I do not expect (1) and (3) to be different from a kernel resource
allocation perspective.

If the core resource layer is asked to assign resources it will,
regardless of what FW programmed in the BARs (the BAR regions size
matters, that's it), I went through pci_bus_assign_resources() a couple
of times and I have to add a bit of debugging so give me the benefit of
the doubt please, but there is nothing that let me think it won't assign
resources (and therefore assign a parent pointer) if the resources are
already programmed correctly (actually I even think the kernel may
change what FW programmed according to its resource alloc policy).

> This last case 3) is the problem.  I'm guessing this case doesn't
> currently occur on arm/arm64, but it's the normal case on x86, and it
> seems perverse that things work if firmware does nothing, but they
> don't work if firmware does more setup.

IIUC X86 claim resources as programmed by FW so it is not really the
same situation as arm64, that claims nothing. Claimed resources are not
reassigned, they are skipped by resource allocation/sizing code
(because their parent pointer is set).

And as I said above even if FW does some set-up that will still work
on ARM/ARM64, otherwise this means that on ALL ARM/ARM64 systems out there
PCI set-up at kernel handover is non-existent, otherwise we would
have resource enablement failures NOW, right ?

> So I think we should add some sort of arm/arm64-specific
> pci_claim_resource() path similar to the pcibios_allocate_resources()
> stuff on x86.

I agree but it has to be done with care in particular in relation to
bridges apertures, claiming resources on systems that currently reassign
everything may trigger regressions.

In particular, having an API that claims resources is NOT sufficient
for that purpose for two reasons:

- If resource claiming fails for some resources, currently the kernel
  spits too much noise in the logs, claiming should be a best-effort
  approach, if it fails there is no error to report in the logs, if FW
  left resources unset that's *not* an error AFAIK
- Bridge apertures: care must be taken so that resources downstream
  should be sized so that bridges can accomodate them, this may require
  releasing previously claimed bridge apertures and realloc them

The approach should be:

(1) Claim resources
(2) Realloc whatever fails (which may imply releasing bridges resources
    previously claimed)

> > As for this patch series, given that:
> > 
> > commit (in -next) 903589ca7165 ("ARM: 8554/1: kernel: pci: remove
> > pci=firmware command line parameter handling") removes the PCI_PROBE_ONLY
> > handling from the (ARM) command line, the PCI host generic becomes the
> > last ARM/ARM64 host controller that requires PCI_PROBE_ONLY to function
> > (depending on DT settings).
> > 
> > The idea behind adding pci_bus_claim_resources (patch 1) to core code
> > was that it could be reused by other arches too, I do not have evidence
> > though, I have to prove it, so I'd rather squash patch 1 into this one
> > and make the code claiming resources local to the PCI host generic,
> > I can't add a generic PCI core API just for one host controller
> > (IMHO we should add an API that allows us to claim bus resources and
> > realloc the ones for which claiming fail - which may mean releasing
> > bridges resources and realloc/resize them - code is in the kernel already
> > I have to write that API).
> > 
> > The code claiming resources on x86, IA64 and PowerPC looks extremely
> > similar but it has to be proven that a generic function has a chance
> > to work, so patch 1 is not really justified at present.
> 
> I don't really object to patch 1, but you're right that it's possible
> we could do a better job later.  I would certainly like to get that
> sort of code (including the pcibios_allocate_resources() stuff I just
> mentioned) out of the arches and into the core somehow.

Problem with patch 1, is that, if resource claiming fails, it spits
loads of noise in kernel logs (actually it is pci_claim_resource(), that
patch 1 uses, that spits errors on claiming failure), that's a detail but
it will make people unhappy.

I do not think that if claiming for a particular resource fails we can
consider it an error that's why I see patch 1 more PCI host generic
PCI_PROBE_ONLY specific rather than anything else, we can't use
it for !PCI_PROBE_ONLY systems unless I rework it to remove the
kernel error logs on resource claiming failures.

Probably on X86/IA64 resource claiming is spotless because on most
if not all systems FW programmes the PCI bus and the kernel can take
the set-up as-is, it is a question since I have no visibility into that.

> > If you have no objections I will squash patch 1 into this one (moving
> > the respective code in PCI host generic driver), and I would not merge
> > this series till the commit above in -next gets in the kernel (which
> > makes sure that PCI_PROBE_ONLY can't be set on the command line, that's
> > fundamental to this series, at least on ARM, on ARM64 DT is the only way
> > PCI_PROBE_ONLY can be set and only on host controllers that check the
> > chosen node property - ie PCI host generic, that we are patching).
> 
> If there's a stable branch containing 903589ca7165 ("ARM: 8554/1:
> kernel: pci: remove pci=firmware command line parameter handling"), I
> can pull that and merge your series on top of it.

I think I should at least split patch 3 in two (one for ARM and one for
ARM64), if Russell is forced to revert the commit above (because
we discover pci=firmware command line users) I do not want ARM64 to
be affected.

Thanks !
Lorenzo
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Arnd Bergmann April 18, 2016, 2:49 p.m. UTC | #5
On Monday 18 April 2016 11:01:54 Lorenzo Pieralisi wrote:
> On Fri, Apr 15, 2016 at 08:08:03AM -0500, Bjorn Helgaas wrote:
> > On Tue, Apr 12, 2016 at 04:48:10PM +0100, Lorenzo Pieralisi wrote:

> > This last case 3) is the problem.  I'm guessing this case doesn't
> > currently occur on arm/arm64, but it's the normal case on x86, and it
> > seems perverse that things work if firmware does nothing, but they
> > don't work if firmware does more setup.
> 
> IIUC X86 claim resources as programmed by FW so it is not really the
> same situation as arm64, that claims nothing. Claimed resources are not
> reassigned, they are skipped by resource allocation/sizing code
> (because their parent pointer is set).
> 
> And as I said above even if FW does some set-up that will still work
> on ARM/ARM64, otherwise this means that on ALL ARM/ARM64 systems out there
> PCI set-up at kernel handover is non-existent, otherwise we would
> have resource enablement failures NOW, right ?

The embedded systems (in which I would count all arm32 machines) tend
to not do proper bus probing in their bootloaders, so we have to do it
ourselves in the kernel.

For server systems (all UEFI based ones), I'd argue that we should
rely on the firmware to do it just like we do on x86, possibly with
a blacklist of known-broken machines on which we have to do it
manually as well. Once ACPI spreads, we will likely see an increasing
number of machines on which we must not reassign the resources or
bad things happen to stuff that is owned by the BIOS.

	Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Lorenzo Pieralisi April 18, 2016, 5:31 p.m. UTC | #6
On Mon, Apr 18, 2016 at 04:49:43PM +0200, Arnd Bergmann wrote:
> On Monday 18 April 2016 11:01:54 Lorenzo Pieralisi wrote:
> > On Fri, Apr 15, 2016 at 08:08:03AM -0500, Bjorn Helgaas wrote:
> > > On Tue, Apr 12, 2016 at 04:48:10PM +0100, Lorenzo Pieralisi wrote:
> 
> > > This last case 3) is the problem.  I'm guessing this case doesn't
> > > currently occur on arm/arm64, but it's the normal case on x86, and it
> > > seems perverse that things work if firmware does nothing, but they
> > > don't work if firmware does more setup.
> > 
> > IIUC X86 claim resources as programmed by FW so it is not really the
> > same situation as arm64, that claims nothing. Claimed resources are not
> > reassigned, they are skipped by resource allocation/sizing code
> > (because their parent pointer is set).
> > 
> > And as I said above even if FW does some set-up that will still work
> > on ARM/ARM64, otherwise this means that on ALL ARM/ARM64 systems out there
> > PCI set-up at kernel handover is non-existent, otherwise we would
> > have resource enablement failures NOW, right ?
> 
> The embedded systems (in which I would count all arm32 machines) tend
> to not do proper bus probing in their bootloaders, so we have to do it
> ourselves in the kernel.
> 
> For server systems (all UEFI based ones), I'd argue that we should
> rely on the firmware to do it just like we do on x86, possibly with
> a blacklist of known-broken machines on which we have to do it
> manually as well. Once ACPI spreads, we will likely see an increasing
> number of machines on which we must not reassign the resources or
> bad things happen to stuff that is owned by the BIOS.

The only way I can pull that off, is by writing an ARM64 PCI resource
allocation function that does the following:

- Try to claim the FW set-up
- Realloc on claiming failures, inclusive of bridges resources
  releasing/resizing

When to call it it has to be seen, either I do it on all ARM64 machines
(but this requires significant testing because regressions are more
than likely given that there are platforms on which we reassign everything
already) or on !acpi_disabled (but I think that's wrong because I do not
see why it is *only* dependent on ACPI), the sooner we implement it the
better (and actually that's the reason why I wanted this function to
be in the ACPI host controller code for ARM64 from the beginning - but
if we do it at arch level it can be even more generic - again, when
to call it it must be decided).

Lorenzo
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bjorn Helgaas April 19, 2016, 9:03 p.m. UTC | #7
On Mon, Apr 18, 2016 at 11:01:54AM +0100, Lorenzo Pieralisi wrote:
> On Fri, Apr 15, 2016 at 08:08:03AM -0500, Bjorn Helgaas wrote:
> > On Tue, Apr 12, 2016 at 04:48:10PM +0100, Lorenzo Pieralisi wrote:
> 
> [...]
> 
> > > > The next patch removes the arm and arm64 pcibios_enable_device()
> > > > implementations, which implies that arm and arm64 only need the generic
> > > > version, which simply calls pci_enable_resources().  That assumes r->parent
> > > > is set.
> > > > 
> > > > After this patch, we'll call pci_bus_claim_resources() for the
> > > > PCI_PROBE_ONLY case, and that sets r->parent for all the resources.
> > > > 
> > > > Where does r->parent get set in the non-PCI_PROBE_ONLY case?  Obviously
> > > > that path *works*, because you're not changing anything there.  I'd just
> > > > like to have a hint that makes this change more obvious.
> > > 
> > > On all ARM/ARM64 PCI controllers drivers I am aware of (apart from the
> > > kvmtool PCI host controller which does require PCI_PROBE_ONLY, so we need
> > > this patch), resources are always reassigned and the core code reassigning
> > > them takes care of assigning their parent pointers too, to answer your
> > > question.
> > 
> > Here's what I find confusing.  Consider these three cases:
> > 
> >   1) Firmware programs no BARs and we reassign everything.  We call
> >   pci_bus_assign_resources(), and the pci_assign_resource() ...
> >   allocate_resource() path makes sure everything is claimed.  This is
> >   apparently the normal arm/arm64 path, and it already works.
> > 
> >   2) Firmware programs all BARs and we set PCI_PROBE_ONLY.  After this
> >   series, we'll claim the resources and remove the PCI_PROBE_ONLY
> >   special case in pcibios_enable_device().  This is great!
> > 
> >   3) Firmware programs all BARs but we don't set PCI_PROBE_ONLY.  We
> >   call pci_bus_assign_resources(), but I think it does nothing because
> >   everything is already assigned.  The resources are not claimed and
> >   pci_enable_resources() will fail.
> 
> I do not expect (1) and (3) to be different from a kernel resource
> allocation perspective.
> 
> If the core resource layer is asked to assign resources it will,
> regardless of what FW programmed in the BARs (the BAR regions size
> matters, that's it), I went through pci_bus_assign_resources() a couple
> of times and I have to add a bit of debugging so give me the benefit of
> the doubt please, but there is nothing that let me think it won't assign
> resources (and therefore assign a parent pointer) if the resources are
> already programmed correctly (actually I even think the kernel may
> change what FW programmed according to its resource alloc policy).

OK.  If you're saying that even if FW programmed the BARs, the core
will assign resources and set r->parent, that's all I'm looking for.
I *would* like a comment where we test PCI_PROBE_ONLY to the effect
that for PCI_PROBE_ONLY we call pci_bus_claim_resources(), and for
!PCI_PROBE_ONLY, we claim the resources in pci_bus_assign_resources().

Bjorn
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/pci/host/pci-host-generic.c b/drivers/pci/host/pci-host-generic.c
index 1652bc7..e529825 100644
--- a/drivers/pci/host/pci-host-generic.c
+++ b/drivers/pci/host/pci-host-generic.c
@@ -252,7 +252,10 @@  static int gen_pci_probe(struct platform_device *pdev)
 
 	pci_fixup_irqs(pci_common_swizzle, of_irq_parse_and_map_pci);
 
-	if (!pci_has_flag(PCI_PROBE_ONLY)) {
+
+	if (pci_has_flag(PCI_PROBE_ONLY)) {
+		pci_bus_claim_resources(bus);
+	} else {
 		pci_bus_size_bridges(bus);
 		pci_bus_assign_resources(bus);