Skip to content

Commit

Permalink
ipmi: Fix a memory ordering issue
Browse files Browse the repository at this point in the history
From a locking point of view it is safe to check waiting_msg without
a lock, but there is a memory ordering issue that causes it to
possibly not be set right when viewed from another processor.  We are
already claiming a lock right after that, move the check to inside
the lock to enforce the memory ordering.

Signed-off-by: Corey Minyard <[email protected]>
  • Loading branch information
cminyard committed Feb 20, 2015
1 parent d6c5dc1 commit 1d86e29
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions drivers/char/ipmi/ipmi_si_intf.c
Original file line number Diff line number Diff line change
Expand Up @@ -932,17 +932,14 @@ static void sender(void *send_info,
enum si_sm_result result;
unsigned long flags;

BUG_ON(smi_info->waiting_msg);
smi_info->waiting_msg = msg;

debug_timestamp("Enqueue");

if (smi_info->run_to_completion) {
/*
* If we are running to completion, start it and run
* transactions until everything is clear.
*/
smi_info->curr_msg = smi_info->waiting_msg;
smi_info->curr_msg = msg;
smi_info->waiting_msg = NULL;

/*
Expand All @@ -960,6 +957,15 @@ static void sender(void *send_info,
}

spin_lock_irqsave(&smi_info->si_lock, flags);
/*
* The following two lines don't need to be under the lock for
* the lock's sake, but they do need SMP memory barriers to
* avoid getting things out of order. We are already claiming
* the lock, anyway, so just do it under the lock to avoid the
* ordering problem.
*/
BUG_ON(smi_info->waiting_msg);
smi_info->waiting_msg = msg;
check_start_timer_thread(smi_info);
spin_unlock_irqrestore(&smi_info->si_lock, flags);
}
Expand Down

0 comments on commit 1d86e29

Please sign in to comment.