提交 e7beed09 编写于 作者: A Al Viro 提交者: Yang Yingliang

epoll: replace ->visited/visited_list with generation count

commit 18306c40 upstream.

removes the need to clear it, along with the races.
Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 39aea67c
...@@ -222,8 +222,7 @@ struct eventpoll { ...@@ -222,8 +222,7 @@ struct eventpoll {
struct file *file; struct file *file;
/* used to optimize loop detection check */ /* used to optimize loop detection check */
int visited; u64 gen;
struct list_head visited_list_link;
#ifdef CONFIG_NET_RX_BUSY_POLL #ifdef CONFIG_NET_RX_BUSY_POLL
/* used to track busy poll napi_id */ /* used to track busy poll napi_id */
...@@ -273,6 +272,8 @@ static long max_user_watches __read_mostly; ...@@ -273,6 +272,8 @@ static long max_user_watches __read_mostly;
*/ */
static DEFINE_MUTEX(epmutex); static DEFINE_MUTEX(epmutex);
static u64 loop_check_gen = 0;
/* Used to check for epoll file descriptor inclusion loops */ /* Used to check for epoll file descriptor inclusion loops */
static struct nested_calls poll_loop_ncalls; static struct nested_calls poll_loop_ncalls;
...@@ -282,9 +283,6 @@ static struct kmem_cache *epi_cache __read_mostly; ...@@ -282,9 +283,6 @@ static struct kmem_cache *epi_cache __read_mostly;
/* Slab cache used to allocate "struct eppoll_entry" */ /* Slab cache used to allocate "struct eppoll_entry" */
static struct kmem_cache *pwq_cache __read_mostly; static struct kmem_cache *pwq_cache __read_mostly;
/* Visited nodes during ep_loop_check(), so we can unset them when we finish */
static LIST_HEAD(visited_list);
/* /*
* List of files with newly added links, where we may need to limit the number * List of files with newly added links, where we may need to limit the number
* of emanating paths. Protected by the epmutex. * of emanating paths. Protected by the epmutex.
...@@ -1869,13 +1867,12 @@ static int ep_loop_check_proc(void *priv, void *cookie, int call_nests) ...@@ -1869,13 +1867,12 @@ static int ep_loop_check_proc(void *priv, void *cookie, int call_nests)
struct epitem *epi; struct epitem *epi;
mutex_lock_nested(&ep->mtx, call_nests + 1); mutex_lock_nested(&ep->mtx, call_nests + 1);
ep->visited = 1; ep->gen = loop_check_gen;
list_add(&ep->visited_list_link, &visited_list);
for (rbp = rb_first_cached(&ep->rbr); rbp; rbp = rb_next(rbp)) { for (rbp = rb_first_cached(&ep->rbr); rbp; rbp = rb_next(rbp)) {
epi = rb_entry(rbp, struct epitem, rbn); epi = rb_entry(rbp, struct epitem, rbn);
if (unlikely(is_file_epoll(epi->ffd.file))) { if (unlikely(is_file_epoll(epi->ffd.file))) {
ep_tovisit = epi->ffd.file->private_data; ep_tovisit = epi->ffd.file->private_data;
if (ep_tovisit->visited) if (ep_tovisit->gen == loop_check_gen)
continue; continue;
error = ep_call_nested(&poll_loop_ncalls, EP_MAX_NESTS, error = ep_call_nested(&poll_loop_ncalls, EP_MAX_NESTS,
ep_loop_check_proc, epi->ffd.file, ep_loop_check_proc, epi->ffd.file,
...@@ -1916,18 +1913,8 @@ static int ep_loop_check_proc(void *priv, void *cookie, int call_nests) ...@@ -1916,18 +1913,8 @@ static int ep_loop_check_proc(void *priv, void *cookie, int call_nests)
*/ */
static int ep_loop_check(struct eventpoll *ep, struct file *file) static int ep_loop_check(struct eventpoll *ep, struct file *file)
{ {
int ret; return ep_call_nested(&poll_loop_ncalls, EP_MAX_NESTS,
struct eventpoll *ep_cur, *ep_next;
ret = ep_call_nested(&poll_loop_ncalls, EP_MAX_NESTS,
ep_loop_check_proc, file, ep, current); ep_loop_check_proc, file, ep, current);
/* clear visited list */
list_for_each_entry_safe(ep_cur, ep_next, &visited_list,
visited_list_link) {
ep_cur->visited = 0;
list_del(&ep_cur->visited_list_link);
}
return ret;
} }
static void clear_tfile_check_list(void) static void clear_tfile_check_list(void)
...@@ -2149,6 +2136,7 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd, ...@@ -2149,6 +2136,7 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
error_tgt_fput: error_tgt_fput:
if (full_check) { if (full_check) {
clear_tfile_check_list(); clear_tfile_check_list();
loop_check_gen++;
mutex_unlock(&epmutex); mutex_unlock(&epmutex);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册