Skip to content

Commit

Permalink
powerpc/kernel: Block interrupts when updating TIDR
Browse files Browse the repository at this point in the history
clear_thread_tidr() is called in interrupt context as a part of delayed
put of the task structure (i.e as a part of timer interrupt). To prevent
a deadlock, block interrupts when holding vas_thread_id_lock to set/
clear TIDR for a task.

Fixes: ec233ed ("powerpc: Add support for setting SPRN_TIDR")
Cc: stable@vger.kernel.org # v4.15+
Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
  • Loading branch information
Sukadev Bhattiprolu authored and Michael Ellerman committed Jan 27, 2018
1 parent 902bdc5 commit 384dfd6
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions arch/powerpc/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -1515,24 +1515,25 @@ static int assign_thread_tidr(void)
{
int index;
int err;
unsigned long flags;

again:
if (!ida_pre_get(&vas_thread_ida, GFP_KERNEL))
return -ENOMEM;

spin_lock(&vas_thread_id_lock);
spin_lock_irqsave(&vas_thread_id_lock, flags);
err = ida_get_new_above(&vas_thread_ida, 1, &index);
spin_unlock(&vas_thread_id_lock);
spin_unlock_irqrestore(&vas_thread_id_lock, flags);

if (err == -EAGAIN)
goto again;
else if (err)
return err;

if (index > MAX_THREAD_CONTEXT) {
spin_lock(&vas_thread_id_lock);
spin_lock_irqsave(&vas_thread_id_lock, flags);
ida_remove(&vas_thread_ida, index);
spin_unlock(&vas_thread_id_lock);
spin_unlock_irqrestore(&vas_thread_id_lock, flags);
return -ENOMEM;
}

Expand All @@ -1541,9 +1542,11 @@ static int assign_thread_tidr(void)

static void free_thread_tidr(int id)
{
spin_lock(&vas_thread_id_lock);
unsigned long flags;

spin_lock_irqsave(&vas_thread_id_lock, flags);
ida_remove(&vas_thread_ida, id);
spin_unlock(&vas_thread_id_lock);
spin_unlock_irqrestore(&vas_thread_id_lock, flags);
}

/*
Expand Down

0 comments on commit 384dfd6

Please sign in to comment.