Commit 83db93f4 authored by Neil Brown's avatar Neil Brown Committed by Greg Kroah-Hartman

sysfs: Allow sysfs_notify_dirent to be called from interrupt context.

sysfs_notify_dirent is a simple atomic operation that can be used to
alert user-space that new data can be read from a sysfs attribute.

Unfortunately it cannot currently be called from non-process context
because of its use of spin_lock which is sometimes taken with
interrupts enabled.

So change all lockers of sysfs_open_dirent_lock to disable interrupts,
thus making sysfs_notify_dirent safe to be called from non-process
context (as drivers/md does in md_safemode_timeout).

sysfs_get_open_dirent is (documented as being) only called from
process context, so it uses spin_lock_irq.  Other places
use spin_lock_irqsave.

The usage for sysfs_notify_dirent in md_safemode_timeout was
introduced in 2.6.28, so this patch is suitable for that and more
recent kernels.
Reported-by: default avatarJoel Andres Granados <jgranado@redhat.com>
Signed-off-by: default avatarNeilBrown <neilb@suse.de>
Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
Cc: stable <stable@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent a6a83577
...@@ -268,7 +268,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd, ...@@ -268,7 +268,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
struct sysfs_open_dirent *od, *new_od = NULL; struct sysfs_open_dirent *od, *new_od = NULL;
retry: retry:
spin_lock(&sysfs_open_dirent_lock); spin_lock_irq(&sysfs_open_dirent_lock);
if (!sd->s_attr.open && new_od) { if (!sd->s_attr.open && new_od) {
sd->s_attr.open = new_od; sd->s_attr.open = new_od;
...@@ -281,7 +281,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd, ...@@ -281,7 +281,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
list_add_tail(&buffer->list, &od->buffers); list_add_tail(&buffer->list, &od->buffers);
} }
spin_unlock(&sysfs_open_dirent_lock); spin_unlock_irq(&sysfs_open_dirent_lock);
if (od) { if (od) {
kfree(new_od); kfree(new_od);
...@@ -315,8 +315,9 @@ static void sysfs_put_open_dirent(struct sysfs_dirent *sd, ...@@ -315,8 +315,9 @@ static void sysfs_put_open_dirent(struct sysfs_dirent *sd,
struct sysfs_buffer *buffer) struct sysfs_buffer *buffer)
{ {
struct sysfs_open_dirent *od = sd->s_attr.open; struct sysfs_open_dirent *od = sd->s_attr.open;
unsigned long flags;
spin_lock(&sysfs_open_dirent_lock); spin_lock_irqsave(&sysfs_open_dirent_lock, flags);
list_del(&buffer->list); list_del(&buffer->list);
if (atomic_dec_and_test(&od->refcnt)) if (atomic_dec_and_test(&od->refcnt))
...@@ -324,7 +325,7 @@ static void sysfs_put_open_dirent(struct sysfs_dirent *sd, ...@@ -324,7 +325,7 @@ static void sysfs_put_open_dirent(struct sysfs_dirent *sd,
else else
od = NULL; od = NULL;
spin_unlock(&sysfs_open_dirent_lock); spin_unlock_irqrestore(&sysfs_open_dirent_lock, flags);
kfree(od); kfree(od);
} }
...@@ -456,8 +457,9 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait) ...@@ -456,8 +457,9 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
void sysfs_notify_dirent(struct sysfs_dirent *sd) void sysfs_notify_dirent(struct sysfs_dirent *sd)
{ {
struct sysfs_open_dirent *od; struct sysfs_open_dirent *od;
unsigned long flags;
spin_lock(&sysfs_open_dirent_lock); spin_lock_irqsave(&sysfs_open_dirent_lock, flags);
od = sd->s_attr.open; od = sd->s_attr.open;
if (od) { if (od) {
...@@ -465,7 +467,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd) ...@@ -465,7 +467,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
wake_up_interruptible(&od->poll); wake_up_interruptible(&od->poll);
} }
spin_unlock(&sysfs_open_dirent_lock); spin_unlock_irqrestore(&sysfs_open_dirent_lock, flags);
} }
EXPORT_SYMBOL_GPL(sysfs_notify_dirent); EXPORT_SYMBOL_GPL(sysfs_notify_dirent);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment