blob: 394f70b17162ef1131c0c0eb04dcb49e55ac717f [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;
Sasha Levinb67bfe02013-02-27 17:06:00 -080037 struct hlist_node *tmp2;
Avi Kivity7c68af62009-09-19 09:40:22 +030038 struct hlist_head *head;
39
40 head = &get_cpu_var(return_notifier_list);
Sasha Levinb67bfe02013-02-27 17:06:00 -080041 hlist_for_each_entry_safe(urn, tmp2, head, link)
Avi Kivity7c68af62009-09-19 09:40:22 +030042 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}