diff options
Diffstat (limited to 'fs/eventpoll.c')
-rw-r--r-- | fs/eventpoll.c | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 2a7dcd6ddc09..739b0985b398 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c | |||
@@ -426,6 +426,31 @@ out_unlock: | |||
426 | return error; | 426 | return error; |
427 | } | 427 | } |
428 | 428 | ||
429 | /* | ||
430 | * As described in commit 0ccf831cb lockdep: annotate epoll | ||
431 | * the use of wait queues used by epoll is done in a very controlled | ||
432 | * manner. Wake ups can nest inside each other, but are never done | ||
433 | * with the same locking. For example: | ||
434 | * | ||
435 | * dfd = socket(...); | ||
436 | * efd1 = epoll_create(); | ||
437 | * efd2 = epoll_create(); | ||
438 | * epoll_ctl(efd1, EPOLL_CTL_ADD, dfd, ...); | ||
439 | * epoll_ctl(efd2, EPOLL_CTL_ADD, efd1, ...); | ||
440 | * | ||
441 | * When a packet arrives to the device underneath "dfd", the net code will | ||
442 | * issue a wake_up() on its poll wake list. Epoll (efd1) has installed a | ||
443 | * callback wakeup entry on that queue, and the wake_up() performed by the | ||
444 | * "dfd" net code will end up in ep_poll_callback(). At this point epoll | ||
445 | * (efd1) notices that it may have some event ready, so it needs to wake up | ||
446 | * the waiters on its poll wait list (efd2). So it calls ep_poll_safewake() | ||
447 | * that ends up in another wake_up(), after having checked about the | ||
448 | * recursion constraints. That are, no more than EP_MAX_POLLWAKE_NESTS, to | ||
449 | * avoid stack blasting. | ||
450 | * | ||
451 | * When CONFIG_DEBUG_LOCK_ALLOC is enabled, make sure lockdep can handle | ||
452 | * this special case of epoll. | ||
453 | */ | ||
429 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | 454 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
430 | static inline void ep_wake_up_nested(wait_queue_head_t *wqueue, | 455 | static inline void ep_wake_up_nested(wait_queue_head_t *wqueue, |
431 | unsigned long events, int subclass) | 456 | unsigned long events, int subclass) |
@@ -698,9 +723,12 @@ static int ep_read_events_proc(struct eventpoll *ep, struct list_head *head, | |||
698 | void *priv) | 723 | void *priv) |
699 | { | 724 | { |
700 | struct epitem *epi, *tmp; | 725 | struct epitem *epi, *tmp; |
726 | poll_table pt; | ||
701 | 727 | ||
728 | init_poll_funcptr(&pt, NULL); | ||
702 | list_for_each_entry_safe(epi, tmp, head, rdllink) { | 729 | list_for_each_entry_safe(epi, tmp, head, rdllink) { |
703 | if (epi->ffd.file->f_op->poll(epi->ffd.file, NULL) & | 730 | pt._key = epi->event.events; |
731 | if (epi->ffd.file->f_op->poll(epi->ffd.file, &pt) & | ||
704 | epi->event.events) | 732 | epi->event.events) |
705 | return POLLIN | POLLRDNORM; | 733 | return POLLIN | POLLRDNORM; |
706 | else { | 734 | else { |
@@ -1048,13 +1076,11 @@ static int reverse_path_check_proc(void *priv, void *cookie, int call_nests) | |||
1048 | */ | 1076 | */ |
1049 | static int reverse_path_check(void) | 1077 | static int reverse_path_check(void) |
1050 | { | 1078 | { |
1051 | int length = 0; | ||
1052 | int error = 0; | 1079 | int error = 0; |
1053 | struct file *current_file; | 1080 | struct file *current_file; |
1054 | 1081 | ||
1055 | /* let's call this for all tfiles */ | 1082 | /* let's call this for all tfiles */ |
1056 | list_for_each_entry(current_file, &tfile_check_list, f_tfile_llink) { | 1083 | list_for_each_entry(current_file, &tfile_check_list, f_tfile_llink) { |
1057 | length++; | ||
1058 | path_count_init(); | 1084 | path_count_init(); |
1059 | error = ep_call_nested(&poll_loop_ncalls, EP_MAX_NESTS, | 1085 | error = ep_call_nested(&poll_loop_ncalls, EP_MAX_NESTS, |
1060 | reverse_path_check_proc, current_file, | 1086 | reverse_path_check_proc, current_file, |
@@ -1096,6 +1122,7 @@ static int ep_insert(struct eventpoll *ep, struct epoll_event *event, | |||
1096 | /* Initialize the poll table using the queue callback */ | 1122 | /* Initialize the poll table using the queue callback */ |
1097 | epq.epi = epi; | 1123 | epq.epi = epi; |
1098 | init_poll_funcptr(&epq.pt, ep_ptable_queue_proc); | 1124 | init_poll_funcptr(&epq.pt, ep_ptable_queue_proc); |
1125 | epq.pt._key = event->events; | ||
1099 | 1126 | ||
1100 | /* | 1127 | /* |
1101 | * Attach the item to the poll hooks and get current event bits. | 1128 | * Attach the item to the poll hooks and get current event bits. |
@@ -1190,6 +1217,9 @@ static int ep_modify(struct eventpoll *ep, struct epitem *epi, struct epoll_even | |||
1190 | { | 1217 | { |
1191 | int pwake = 0; | 1218 | int pwake = 0; |
1192 | unsigned int revents; | 1219 | unsigned int revents; |
1220 | poll_table pt; | ||
1221 | |||
1222 | init_poll_funcptr(&pt, NULL); | ||
1193 | 1223 | ||
1194 | /* | 1224 | /* |
1195 | * Set the new event interest mask before calling f_op->poll(); | 1225 | * Set the new event interest mask before calling f_op->poll(); |
@@ -1197,13 +1227,14 @@ static int ep_modify(struct eventpoll *ep, struct epitem *epi, struct epoll_even | |||
1197 | * f_op->poll() call and the new event set registering. | 1227 | * f_op->poll() call and the new event set registering. |
1198 | */ | 1228 | */ |
1199 | epi->event.events = event->events; | 1229 | epi->event.events = event->events; |
1230 | pt._key = event->events; | ||
1200 | epi->event.data = event->data; /* protected by mtx */ | 1231 | epi->event.data = event->data; /* protected by mtx */ |
1201 | 1232 | ||
1202 | /* | 1233 | /* |
1203 | * Get current event bits. We can safely use the file* here because | 1234 | * Get current event bits. We can safely use the file* here because |
1204 | * its usage count has been increased by the caller of this function. | 1235 | * its usage count has been increased by the caller of this function. |
1205 | */ | 1236 | */ |
1206 | revents = epi->ffd.file->f_op->poll(epi->ffd.file, NULL); | 1237 | revents = epi->ffd.file->f_op->poll(epi->ffd.file, &pt); |
1207 | 1238 | ||
1208 | /* | 1239 | /* |
1209 | * If the item is "hot" and it is not registered inside the ready | 1240 | * If the item is "hot" and it is not registered inside the ready |
@@ -1238,6 +1269,9 @@ static int ep_send_events_proc(struct eventpoll *ep, struct list_head *head, | |||
1238 | unsigned int revents; | 1269 | unsigned int revents; |
1239 | struct epitem *epi; | 1270 | struct epitem *epi; |
1240 | struct epoll_event __user *uevent; | 1271 | struct epoll_event __user *uevent; |
1272 | poll_table pt; | ||
1273 | |||
1274 | init_poll_funcptr(&pt, NULL); | ||
1241 | 1275 | ||
1242 | /* | 1276 | /* |
1243 | * We can loop without lock because we are passed a task private list. | 1277 | * We can loop without lock because we are passed a task private list. |
@@ -1250,7 +1284,8 @@ static int ep_send_events_proc(struct eventpoll *ep, struct list_head *head, | |||
1250 | 1284 | ||
1251 | list_del_init(&epi->rdllink); | 1285 | list_del_init(&epi->rdllink); |
1252 | 1286 | ||
1253 | revents = epi->ffd.file->f_op->poll(epi->ffd.file, NULL) & | 1287 | pt._key = epi->event.events; |
1288 | revents = epi->ffd.file->f_op->poll(epi->ffd.file, &pt) & | ||
1254 | epi->event.events; | 1289 | epi->event.events; |
1255 | 1290 | ||
1256 | /* | 1291 | /* |