Commit b8acb808 authored by Max Asbock's avatar Max Asbock Committed by Linus Torvalds

[PATCH] ibmasm driver: correctly wake up sleeping threads

Due to my incomplete understanding of the wait_event_interruptible() function
threads waiting for service processor events were not woken up.  This patch
fixes that problem.
Signed-off-by: default avatarMax Asbock <masbock@us.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent f5ccc842
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
*/ */
#include "ibmasm.h" #include "ibmasm.h"
#include "lowlevel.h"
/* /*
* ASM service processor event handling routines. * ASM service processor event handling routines.
...@@ -34,7 +35,6 @@ ...@@ -34,7 +35,6 @@
* circular buffer. * circular buffer.
*/ */
static void wake_up_event_readers(struct service_processor *sp) static void wake_up_event_readers(struct service_processor *sp)
{ {
struct event_reader *reader; struct event_reader *reader;
...@@ -63,7 +63,7 @@ void ibmasm_receive_event(struct service_processor *sp, void *data, unsigned int ...@@ -63,7 +63,7 @@ void ibmasm_receive_event(struct service_processor *sp, void *data, unsigned int
spin_lock_irqsave(&sp->lock, flags); spin_lock_irqsave(&sp->lock, flags);
/* copy the event into the next slot in the circular buffer */ /* copy the event into the next slot in the circular buffer */
event = &buffer->events[buffer->next_index]; event = &buffer->events[buffer->next_index];
memcpy(event->data, data, data_size); memcpy_fromio(event->data, data, data_size);
event->data_size = data_size; event->data_size = data_size;
event->serial_number = buffer->next_serial_number; event->serial_number = buffer->next_serial_number;
...@@ -93,7 +93,10 @@ int ibmasm_get_next_event(struct service_processor *sp, struct event_reader *rea ...@@ -93,7 +93,10 @@ int ibmasm_get_next_event(struct service_processor *sp, struct event_reader *rea
unsigned int index; unsigned int index;
unsigned long flags; unsigned long flags;
if (wait_event_interruptible(reader->wait, event_available(buffer, reader))) reader->cancelled = 0;
if (wait_event_interruptible(reader->wait,
event_available(buffer, reader) || reader->cancelled))
return -ERESTARTSYS; return -ERESTARTSYS;
if (!event_available(buffer, reader)) if (!event_available(buffer, reader))
...@@ -116,6 +119,12 @@ int ibmasm_get_next_event(struct service_processor *sp, struct event_reader *rea ...@@ -116,6 +119,12 @@ int ibmasm_get_next_event(struct service_processor *sp, struct event_reader *rea
return event->data_size; return event->data_size;
} }
void ibmasm_cancel_next_event(struct event_reader *reader)
{
reader->cancelled = 1;
wake_up_interruptible(&reader->wait);
}
void ibmasm_event_reader_register(struct service_processor *sp, struct event_reader *reader) void ibmasm_event_reader_register(struct service_processor *sp, struct event_reader *reader)
{ {
unsigned long flags; unsigned long flags;
...@@ -131,8 +140,6 @@ void ibmasm_event_reader_unregister(struct service_processor *sp, struct event_r ...@@ -131,8 +140,6 @@ void ibmasm_event_reader_unregister(struct service_processor *sp, struct event_r
{ {
unsigned long flags; unsigned long flags;
wake_up_interruptible(&reader->wait);
spin_lock_irqsave(&sp->lock, flags); spin_lock_irqsave(&sp->lock, flags);
list_del(&reader->node); list_del(&reader->node);
spin_unlock_irqrestore(&sp->lock, flags); spin_unlock_irqrestore(&sp->lock, flags);
...@@ -164,6 +171,5 @@ int ibmasm_event_buffer_init(struct service_processor *sp) ...@@ -164,6 +171,5 @@ int ibmasm_event_buffer_init(struct service_processor *sp)
void ibmasm_event_buffer_exit(struct service_processor *sp) void ibmasm_event_buffer_exit(struct service_processor *sp)
{ {
wake_up_event_readers(sp);
kfree(sp->event_buffer); kfree(sp->event_buffer);
} }
...@@ -108,6 +108,7 @@ struct event_buffer { ...@@ -108,6 +108,7 @@ struct event_buffer {
}; };
struct event_reader { struct event_reader {
int cancelled;
unsigned int next_serial_number; unsigned int next_serial_number;
wait_queue_head_t wait; wait_queue_head_t wait;
struct list_head node; struct list_head node;
...@@ -185,6 +186,7 @@ extern void ibmasm_receive_event(struct service_processor *sp, void *data, unsi ...@@ -185,6 +186,7 @@ extern void ibmasm_receive_event(struct service_processor *sp, void *data, unsi
extern void ibmasm_event_reader_register(struct service_processor *sp, struct event_reader *reader); extern void ibmasm_event_reader_register(struct service_processor *sp, struct event_reader *reader);
extern void ibmasm_event_reader_unregister(struct service_processor *sp, struct event_reader *reader); extern void ibmasm_event_reader_unregister(struct service_processor *sp, struct event_reader *reader);
extern int ibmasm_get_next_event(struct service_processor *sp, struct event_reader *reader); extern int ibmasm_get_next_event(struct service_processor *sp, struct event_reader *reader);
extern void ibmasm_cancel_next_event(struct event_reader *reader);
/* heartbeat - from SP to OS */ /* heartbeat - from SP to OS */
extern void ibmasm_register_panic_notifier(void); extern void ibmasm_register_panic_notifier(void);
......
...@@ -374,6 +374,7 @@ static int event_file_open(struct inode *inode, struct file *file) ...@@ -374,6 +374,7 @@ static int event_file_open(struct inode *inode, struct file *file)
ibmasm_event_reader_register(sp, &event_data->reader); ibmasm_event_reader_register(sp, &event_data->reader);
event_data->sp = sp; event_data->sp = sp;
event_data->active = 0;
file->private_data = event_data; file->private_data = event_data;
return 0; return 0;
} }
...@@ -391,7 +392,9 @@ static ssize_t event_file_read(struct file *file, char __user *buf, size_t count ...@@ -391,7 +392,9 @@ static ssize_t event_file_read(struct file *file, char __user *buf, size_t count
{ {
struct ibmasmfs_event_data *event_data = file->private_data; struct ibmasmfs_event_data *event_data = file->private_data;
struct event_reader *reader = &event_data->reader; struct event_reader *reader = &event_data->reader;
struct service_processor *sp = event_data->sp;
int ret; int ret;
unsigned long flags;
if (*offset < 0) if (*offset < 0)
return -EINVAL; return -EINVAL;
...@@ -400,17 +403,32 @@ static ssize_t event_file_read(struct file *file, char __user *buf, size_t count ...@@ -400,17 +403,32 @@ static ssize_t event_file_read(struct file *file, char __user *buf, size_t count
if (*offset != 0) if (*offset != 0)
return 0; return 0;
ret = ibmasm_get_next_event(event_data->sp, reader); spin_lock_irqsave(&sp->lock, flags);
if (event_data->active) {
spin_unlock_irqrestore(&sp->lock, flags);
return -EBUSY;
}
event_data->active = 1;
spin_unlock_irqrestore(&sp->lock, flags);
ret = ibmasm_get_next_event(sp, reader);
if (ret <= 0) if (ret <= 0)
return ret; goto out;
if (count < reader->data_size) if (count < reader->data_size) {
return -EINVAL; ret = -EINVAL;
goto out;
}
if (copy_to_user(buf, reader->data, reader->data_size)) if (copy_to_user(buf, reader->data, reader->data_size)) {
return -EFAULT; ret = -EFAULT;
goto out;
}
ret = reader->data_size;
return reader->data_size; out:
event_data->active = 0;
return ret;
} }
static ssize_t event_file_write(struct file *file, const char __user *buf, size_t count, loff_t *offset) static ssize_t event_file_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
...@@ -424,7 +442,7 @@ static ssize_t event_file_write(struct file *file, const char __user *buf, size_ ...@@ -424,7 +442,7 @@ static ssize_t event_file_write(struct file *file, const char __user *buf, size_
if (*offset != 0) if (*offset != 0)
return 0; return 0;
wake_up_interruptible(&event_data->reader.wait); ibmasm_cancel_next_event(&event_data->reader);
return 0; return 0;
} }
......
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