blob: 1744bb80f1fb41ff9f74df1df0d66fdde3f44b9d [file] [log] [blame]
Avi Kivity7c68af62009-09-19 09:40:22 +03001
2#include <linux/user-return-notifier.h>
3#include <linux/percpu.h>
4#include <linux/sched.h>
Paul Gortmaker9984de12011-05-23 14:51:41 -04005#include <linux/export.h>
Avi Kivity7c68af62009-09-19 09:40:22 +03006
7static DEFINE_PER_CPU(struct hlist_head, return_notifier_list);
8
Avi Kivity7c68af62009-09-19 09:40:22 +03009/*
10 * Request a notification when the current cpu returns to userspace. Must be
11 * called in atomic context. The notifier will also be called in atomic
12 * context.
13 */
14void user_return_notifier_register(struct user_return_notifier *urn)
15{
16 set_tsk_thread_flag(current, TIF_USER_RETURN_NOTIFY);
Avi Kivity1786bf02009-11-30 12:54:51 +020017 hlist_add_head(&urn->link, &__get_cpu_var(return_notifier_list));
Avi Kivity7c68af62009-09-19 09:40:22 +030018}
19EXPORT_SYMBOL_GPL(user_return_notifier_register);
20
21/*
22 * Removes a registered user return notifier. Must be called from atomic
Lucas De Marchi25985ed2011-03-30 22:57:33 -030023 * context, and from the same cpu registration occurred in.
Avi Kivity7c68af62009-09-19 09:40:22 +030024 */
25void user_return_notifier_unregister(struct user_return_notifier *urn)
26{
27 hlist_del(&urn->link);
Avi Kivity1786bf02009-11-30 12:54:51 +020028 if (hlist_empty(&__get_cpu_var(return_notifier_list)))
Avi Kivity7c68af62009-09-19 09:40:22 +030029 clear_tsk_thread_flag(current, TIF_USER_RETURN_NOTIFY);
30}
31EXPORT_SYMBOL_GPL(user_return_notifier_unregister);
32
33/* Calls registered user return notifiers */
34void fire_user_return_notifiers(void)
35{
36 struct user_return_notifier *urn;
37 struct hlist_node *tmp1, *tmp2;
38 struct hlist_head *head;
39
40 head = &get_cpu_var(return_notifier_list);
41 hlist_for_each_entry_safe(urn, tmp1, tmp2, head, link)
42 urn->on_user_return(urn);
Stephen Rothwell3c912b62009-11-02 16:17:22 +110043 put_cpu_var(return_notifier_list);
Avi Kivity7c68af62009-09-19 09:40:22 +030044}