Skip to content

Commit

Permalink
[PATCH] oprofile: fix potential deadlock on oprofilefs_lock
Browse files Browse the repository at this point in the history
nmi_cpu_setup() is called from hardirq context and acquires oprofilefs_lock.
alloc_event_buffer() and oprofilefs_ulong_from_user() acquire this lock
without disabling irqs, which could deadlock.

Signed-off-by: Jiri Kosina <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Jiri Kosina authored and Linus Torvalds committed Mar 28, 2007
1 parent 6faee84 commit 4dfc896
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions drivers/oprofile/event_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ void wake_up_buffer_waiter(void)
int alloc_event_buffer(void)
{
int err = -ENOMEM;
unsigned long flags;

spin_lock(&oprofilefs_lock);
spin_lock_irqsave(&oprofilefs_lock, flags);
buffer_size = fs_buffer_size;
buffer_watershed = fs_buffer_watershed;
spin_unlock(&oprofilefs_lock);
spin_unlock_irqrestore(&oprofilefs_lock, flags);

if (buffer_watershed >= buffer_size)
return -EINVAL;
Expand Down
5 changes: 3 additions & 2 deletions drivers/oprofile/oprofilefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ ssize_t oprofilefs_ulong_to_user(unsigned long val, char __user * buf, size_t co
int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count)
{
char tmpbuf[TMPBUFSIZE];
unsigned long flags;

if (!count)
return 0;
Expand All @@ -77,9 +78,9 @@ int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, siz
if (copy_from_user(tmpbuf, buf, count))
return -EFAULT;

spin_lock(&oprofilefs_lock);
spin_lock_irqsave(&oprofilefs_lock, flags);
*val = simple_strtoul(tmpbuf, NULL, 0);
spin_unlock(&oprofilefs_lock);
spin_unlock_irqrestore(&oprofilefs_lock, flags);
return 0;
}

Expand Down

0 comments on commit 4dfc896

Please sign in to comment.