Skip to content

Commit

Permalink
core/pci: Add missing lock in set_power_timer
Browse files Browse the repository at this point in the history
set_power_timer() was not using any lock, though it alters the slot
state and devices found under it. There's a remote possibility that
set_power_timer() is called through check_timers() by a thread already
holding the phb lock, so we try to take the lock but yield and rearm
the timer if somebody else is already owning it. There really
shouldn't be any contention here.

Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com>
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
  • Loading branch information
fbarrat authored and oohal committed Oct 22, 2019
1 parent f6f247a commit 38e51a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/pci-opal.c
Expand Up @@ -674,6 +674,12 @@ static void set_power_timer(struct timer *t __unused, void *data,
struct pci_device *pd = slot->pd;
struct dt_node *dn = pd->dn;
uint8_t link;
struct phb *phb = slot->phb;

if (!phb_try_lock(phb)) {
schedule_timer(&slot->timer, msecs_to_tb(10));
return;
}

switch (slot->state) {
case PCI_SLOT_STATE_SPOWER_START:
Expand Down Expand Up @@ -720,6 +726,7 @@ static void set_power_timer(struct timer *t __unused, void *data,
prlog(PR_ERR, "PCI SLOT %016llx: Unexpected state 0x%08x\n",
slot->id, slot->state);
}
phb_unlock(phb);
}

static int64_t opal_pci_set_power_state(uint64_t async_token,
Expand Down
5 changes: 5 additions & 0 deletions include/pci.h
Expand Up @@ -390,6 +390,11 @@ static inline void phb_lock(struct phb *phb)
lock(&phb->lock);
}

static inline bool phb_try_lock(struct phb *phb)
{
return try_lock(&phb->lock);
}

static inline void phb_unlock(struct phb *phb)
{
unlock(&phb->lock);
Expand Down

0 comments on commit 38e51a3

Please sign in to comment.