Commit 3dc86ca6 authored by SeongJae Park's avatar SeongJae Park Committed by Juergen Gross

xen/xenbus: Count pending messages for each watch

This commit adds a counter of pending messages for each watch in the
struct.  It is used to skip unnecessary pending messages lookup in
'unregister_xenbus_watch()'.  It could also be used in 'will_handle'
callback.

This is part of XSA-349

Cc: stable@vger.kernel.org
Signed-off-by: default avatarSeongJae Park <sjpark@amazon.de>
Reported-by: default avatarMichael Kurth <mku@amazon.de>
Reported-by: default avatarPawel Wieczorkiewicz <wipawel@amazon.de>
Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
parent be987200
...@@ -711,6 +711,7 @@ int xs_watch_msg(struct xs_watch_event *event) ...@@ -711,6 +711,7 @@ int xs_watch_msg(struct xs_watch_event *event)
event->path, event->token))) { event->path, event->token))) {
spin_lock(&watch_events_lock); spin_lock(&watch_events_lock);
list_add_tail(&event->list, &watch_events); list_add_tail(&event->list, &watch_events);
event->handle->nr_pending++;
wake_up(&watch_events_waitq); wake_up(&watch_events_waitq);
spin_unlock(&watch_events_lock); spin_unlock(&watch_events_lock);
} else } else
...@@ -768,6 +769,8 @@ int register_xenbus_watch(struct xenbus_watch *watch) ...@@ -768,6 +769,8 @@ int register_xenbus_watch(struct xenbus_watch *watch)
sprintf(token, "%lX", (long)watch); sprintf(token, "%lX", (long)watch);
watch->nr_pending = 0;
down_read(&xs_watch_rwsem); down_read(&xs_watch_rwsem);
spin_lock(&watches_lock); spin_lock(&watches_lock);
...@@ -817,11 +820,14 @@ void unregister_xenbus_watch(struct xenbus_watch *watch) ...@@ -817,11 +820,14 @@ void unregister_xenbus_watch(struct xenbus_watch *watch)
/* Cancel pending watch events. */ /* Cancel pending watch events. */
spin_lock(&watch_events_lock); spin_lock(&watch_events_lock);
list_for_each_entry_safe(event, tmp, &watch_events, list) { if (watch->nr_pending) {
if (event->handle != watch) list_for_each_entry_safe(event, tmp, &watch_events, list) {
continue; if (event->handle != watch)
list_del(&event->list); continue;
kfree(event); list_del(&event->list);
kfree(event);
}
watch->nr_pending = 0;
} }
spin_unlock(&watch_events_lock); spin_unlock(&watch_events_lock);
...@@ -868,7 +874,6 @@ void xs_suspend_cancel(void) ...@@ -868,7 +874,6 @@ void xs_suspend_cancel(void)
static int xenwatch_thread(void *unused) static int xenwatch_thread(void *unused)
{ {
struct list_head *ent;
struct xs_watch_event *event; struct xs_watch_event *event;
xenwatch_pid = current->pid; xenwatch_pid = current->pid;
...@@ -883,13 +888,15 @@ static int xenwatch_thread(void *unused) ...@@ -883,13 +888,15 @@ static int xenwatch_thread(void *unused)
mutex_lock(&xenwatch_mutex); mutex_lock(&xenwatch_mutex);
spin_lock(&watch_events_lock); spin_lock(&watch_events_lock);
ent = watch_events.next; event = list_first_entry_or_null(&watch_events,
if (ent != &watch_events) struct xs_watch_event, list);
list_del(ent); if (event) {
list_del(&event->list);
event->handle->nr_pending--;
}
spin_unlock(&watch_events_lock); spin_unlock(&watch_events_lock);
if (ent != &watch_events) { if (event) {
event = list_entry(ent, struct xs_watch_event, list);
event->handle->callback(event->handle, event->path, event->handle->callback(event->handle, event->path,
event->token); event->token);
kfree(event); kfree(event);
......
...@@ -61,6 +61,8 @@ struct xenbus_watch ...@@ -61,6 +61,8 @@ struct xenbus_watch
/* Path being watched. */ /* Path being watched. */
const char *node; const char *node;
unsigned int nr_pending;
/* /*
* Called just before enqueing new event while a spinlock is held. * Called just before enqueing new event while a spinlock is held.
* The event will be discarded if this callback returns false. * The event will be discarded if this callback returns false.
......
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