Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1538193

Re: [PATCH 3/3] pciehp: Fix race condition handling surprise link-down

From Keith Busch <keith.busch@intel.com>
Newsgroups linux.kernel
Subject Re: [PATCH 3/3] pciehp: Fix race condition handling surprise link-down
Date 2016-12-08 01:00 +0100
Message-ID <sLUhY-6TP-7@gated-at.bofh.it> (permalink)
References <sF9lL-2x2-3@gated-at.bofh.it> <sF9lL-2x2-5@gated-at.bofh.it> <sLU8i-6PU-19@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Wed, Dec 07, 2016 at 05:40:54PM -0600, Bjorn Helgaas wrote:
> On Sat, Nov 19, 2016 at 12:32:47AM -0800, Ashok Raj wrote:
> > --- a/drivers/pci/hotplug/pciehp_ctrl.c
> > +++ b/drivers/pci/hotplug/pciehp_ctrl.c
> > @@ -182,6 +182,7 @@ static void pciehp_power_thread(struct work_struct *work)
> >  	switch (info->req) {
> >  	case DISABLE_REQ:
> >  		mutex_lock(&p_slot->hotplug_lock);
> > +		p_slot->state = POWEROFF_STATE;
> 
> It sounds right that p_slot->state should be protected.
> 
> It looks like handle_button_press_event() and
> pciehp_sysfs_enable_slot() hold p_slot->lock while updating
> p_slot->state.
> 
> You're setting "state = POWEROFF_STATE" while holding
> p_slot->hotplug_lock (not p_slot->lock).  Four lines down, we set
> "state = STATIC_STATE", but this time we're holding p_slot->lock.
> 
> What is the difference between the p_slot->lock and
> p_slot->hotplug_lock?  Do we need both?  How do we know which one to
> use?
> 
> I'm very confused.

This is _very_ confusing. :)

The p_slot->hotplug_lock serializes a power off and a power on event. We
only want to set the state when one of those events gets to execute
rather than when the event is queued. Changing the state when the event
is queued can trigger a never ending up-down sequence.

It currently looks safe to nest the p_slot->lock under the
p_slot->hotplug_lock if that is you recommendation.

Alternatively we could fix this if we used an ordered work queue for
the slot's work, but that is a significantly more complex change.

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [PATCH 3/3] pciehp: Fix race condition handling surprise  link-down Bjorn Helgaas <helgaas@kernel.org> - 2016-12-08 00:50 +0100
  Re: [PATCH 3/3] pciehp: Fix race condition handling surprise  link-down Keith Busch <keith.busch@intel.com> - 2016-12-08 01:00 +0100
    Re: [PATCH 3/3] pciehp: Fix race condition handling surprise  link-down Bjorn Helgaas <helgaas@kernel.org> - 2016-12-08 16:20 +0100
      Re: [PATCH 3/3] pciehp: Fix race condition handling surprise  link-down Keith Busch <keith.busch@intel.com> - 2016-12-08 18:20 +0100
        Re: [PATCH 3/3] pciehp: Fix race condition handling surprise  link-down Bjorn Helgaas <helgaas@kernel.org> - 2016-12-08 19:00 +0100
          Re: [PATCH 3/3] pciehp: Fix race condition handling surprise  link-down "Raj, Ashok" <ashok.raj@intel.com> - 2016-12-09 22:20 +0100

csiph-web