Re: [PATCH v2] PCI: pciehp: Check link state before accessing device during removal

From: Guenter Roeck
Date: Thu Dec 11 2014 - 16:40:08 EST


On Thu, Dec 11, 2014 at 02:00:06PM -0700, Bjorn Helgaas wrote:
> On Thu, Dec 11, 2014 at 1:45 PM, Guenter Roeck <groeck@xxxxxxxxxxx> wrote:
> > On Thu, Dec 11, 2014 at 01:26:47PM -0700, Bjorn Helgaas wrote:
> >> On Thu, Dec 11, 2014 at 9:38 AM, Guenter Roeck <groeck@xxxxxxxxxxx> wrote:
> >> > On Wed, Dec 10, 2014 at 05:26:30PM -0700, Bjorn Helgaas wrote:
> >> >> On Thu, Nov 20, 2014 at 02:54:24PM -0800, Rajat Jain wrote:
>
> >> >> If we do need it (and it looks like most or all hotplug drivers copied it),
> >> >> isn't there still a race? Can't we have the following sequence?
> >> >>
> >> >> - pciehp_check_link_active() # returns true
> >> >> - Link goes down
> >> >> - pci_read_config_byte() # fails because link is down
> >> >>
> >> > I would guess so. Question is how to address it. Read the configuration byte
> >> > first, then check if the link is down ? Check if link is still up after reading
> >> > the configuration byte ? Add a note that there may be a potential race condition
> >> > and do nothing until it is actually seen ?
> >>
> >> I think we should just read PCI_BRIDGE_CONTROL and look for a 0xff
> >> value. That's not a legal value for the register, so if we see it, it
> >> should be pretty safe to assume the link is down or the device is not
> >> present at all.
> >>
> > Something like
> > if (bctl != 0xff && (bctl & PCI_BRIDGE_CTL_VGA)) {
> > in addition to Rajat's changes ?
> >
> > I think it would be good to keep the change Rajat proposed, ie to check
> > the link state instead of presence. Question then is if you'd want a new
> > revision of Rajat's patch or another patch on top of it with the bctl
> > related change.
>
> Why do we need the link state or the presence check? It seems like
> those are sort of a 90% solution, and doing them provides the illusion
> of value but without real value. If we think that checking for 0xff
> is a 100% solution, we should rely on that and not bother with
> anything else.
>
Interesting thought. Let me play with that.

Guenter
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/