linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@ZenIV.linux.org.uk>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	Marc Zyngier <maz@kernel.org>
Subject: [RFC PATCH 07/27] untangling ep_call_nested(): and there was much rejoicing
Date: Sun,  4 Oct 2020 03:39:09 +0100	[thread overview]
Message-ID: <20201004023929.2740074-7-viro@ZenIV.linux.org.uk> (raw)
In-Reply-To: <20201004023929.2740074-1-viro@ZenIV.linux.org.uk>

From: Al Viro <viro@zeniv.linux.org.uk>

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/eventpoll.c | 43 +++++++++++--------------------------------
 1 file changed, 11 insertions(+), 32 deletions(-)

diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 9a6ee5991f3d..8c3b02755a50 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -439,25 +439,6 @@ static bool ep_push_nested(void *cookie)
 	return true;
 }
 
-/**
- * ep_call_nested - Perform a bound (possibly) nested call, by checking
- *                  that the recursion limit is not exceeded, and that
- *                  the same nested call (by the meaning of same cookie) is
- *                  no re-entered.
- *
- * @nproc: Nested call core function pointer.
- * @priv: Opaque data to be passed to the @nproc callback.
- * @cookie: Cookie to be used to identify this nested call.
- *
- * Returns: Returns the code returned by the @nproc callback, or -1 if
- *          the maximum recursion limit has been exceeded.
- */
-static int ep_call_nested(int (*nproc)(void *, void *, int), void *priv,
-			  void *cookie)
-{
-	return (*nproc)(priv, cookie, nesting);
-}
-
 /*
  * As described in commit 0ccf831cb lockdep: annotate epoll
  * the use of wait queues used by epoll is done in a very controlled
@@ -1325,7 +1306,7 @@ static void path_count_init(void)
 		path_count[i] = 0;
 }
 
-static int reverse_path_check_proc(void *priv, void *cookie, int call_nests)
+static int reverse_path_check_proc(void *priv, void *cookie, int depth)
 {
 	int error = 0;
 	struct file *file = priv;
@@ -1341,13 +1322,13 @@ static int reverse_path_check_proc(void *priv, void *cookie, int call_nests)
 		child_file = epi->ep->file;
 		if (is_file_epoll(child_file)) {
 			if (list_empty(&child_file->f_ep_links)) {
-				if (path_count_inc(call_nests)) {
+				if (path_count_inc(depth)) {
 					error = -1;
 					break;
 				}
 			} else {
-				error = ep_call_nested(reverse_path_check_proc,
-							child_file, child_file);
+				error = reverse_path_check_proc(child_file, child_file,
+								depth + 1);
 			}
 			if (error != 0)
 				break;
@@ -1379,8 +1360,7 @@ static int reverse_path_check(void)
 	/* let's call this for all tfiles */
 	list_for_each_entry(current_file, &tfile_check_list, f_tfile_llink) {
 		path_count_init();
-		error = ep_call_nested(reverse_path_check_proc, current_file,
-					current_file);
+		error = reverse_path_check_proc(current_file, current_file, 0);
 		if (error)
 			break;
 	}
@@ -1886,8 +1866,7 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
 }
 
 /**
- * ep_loop_check_proc - Callback function to be passed to the @ep_call_nested()
- *                      API, to verify that adding an epoll file inside another
+ * ep_loop_check_proc - verify that adding an epoll file inside another
  *                      epoll structure, does not violate the constraints, in
  *                      terms of closed loops, or too deep chains (which can
  *                      result in excessive stack usage).
@@ -1900,7 +1879,7 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
  * Returns: Returns zero if adding the epoll @file inside current epoll
  *          structure @ep does not violate the constraints, or -1 otherwise.
  */
-static int ep_loop_check_proc(void *priv, void *cookie, int call_nests)
+static int ep_loop_check_proc(void *priv, void *cookie, int depth)
 {
 	int error = 0;
 	struct file *file = priv;
@@ -1912,7 +1891,7 @@ static int ep_loop_check_proc(void *priv, void *cookie, int call_nests)
 	if (!ep_push_nested(cookie)) /* limits recursion */
 		return -1;
 
-	mutex_lock_nested(&ep->mtx, call_nests + 1);
+	mutex_lock_nested(&ep->mtx, depth + 1);
 	ep->gen = loop_check_gen;
 	for (rbp = rb_first_cached(&ep->rbr); rbp; rbp = rb_next(rbp)) {
 		epi = rb_entry(rbp, struct epitem, rbn);
@@ -1920,8 +1899,8 @@ static int ep_loop_check_proc(void *priv, void *cookie, int call_nests)
 			ep_tovisit = epi->ffd.file->private_data;
 			if (ep_tovisit->gen == loop_check_gen)
 				continue;
-			error = ep_call_nested(ep_loop_check_proc, epi->ffd.file,
-					ep_tovisit);
+			error = ep_loop_check_proc(epi->ffd.file, ep_tovisit,
+						   depth + 1);
 			if (error != 0)
 				break;
 		} else {
@@ -1959,7 +1938,7 @@ static int ep_loop_check_proc(void *priv, void *cookie, int call_nests)
  */
 static int ep_loop_check(struct eventpoll *ep, struct file *file)
 {
-	return ep_call_nested(ep_loop_check_proc, file, ep);
+	return ep_loop_check_proc(file, ep, 0);
 }
 
 static void clear_tfile_check_list(void)
-- 
2.11.0


  parent reply	other threads:[~2020-10-04  2:39 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-04  2:36 [RFC][PATCHSET] epoll cleanups Al Viro
2020-10-04  2:39 ` [RFC PATCH 01/27] epoll: switch epitem->pwqlist to single-linked list Al Viro
2020-10-04  2:39   ` [RFC PATCH 02/27] epoll: get rid of epitem->nwait Al Viro
2020-10-04  2:39   ` [RFC PATCH 03/27] untangling ep_call_nested(): get rid of useless arguments Al Viro
2020-10-04  2:39   ` [RFC PATCH 04/27] untangling ep_call_nested(): it's all serialized on epmutex Al Viro
2020-10-04  2:39   ` [RFC PATCH 05/27] untangling ep_call_nested(): take pushing cookie into a helper Al Viro
2020-10-04  2:39   ` [RFC PATCH 06/27] untangling ep_call_nested(): move push/pop of cookie into the callbacks Al Viro
2020-10-04  2:39   ` Al Viro [this message]
2020-10-04  2:39   ` [RFC PATCH 08/27] reverse_path_check_proc(): sane arguments Al Viro
2020-10-04  2:39   ` [RFC PATCH 09/27] reverse_path_check_proc(): don't bother with cookies Al Viro
2020-10-04  2:39   ` [RFC PATCH 10/27] clean reverse_path_check_proc() a bit Al Viro
2020-10-04  2:39   ` [RFC PATCH 11/27] ep_loop_check_proc(): lift pushing the cookie into callers Al Viro
2020-10-04  2:39   ` [RFC PATCH 12/27] get rid of ep_push_nested() Al Viro
2020-10-04  2:39   ` [RFC PATCH 13/27] ep_loop_check_proc(): saner calling conventions Al Viro
2020-10-04  2:39   ` [RFC PATCH 14/27] ep_scan_ready_list(): prepare to splitup Al Viro
2020-10-04  2:39   ` [RFC PATCH 15/27] lift the calls of ep_read_events_proc() into the callers Al Viro
2020-10-04  2:39   ` [RFC PATCH 16/27] lift the calls of ep_send_events_proc() " Al Viro
2020-10-04  2:39   ` [RFC PATCH 17/27] ep_send_events_proc(): fold into the caller Al Viro
2020-10-04  2:39   ` [RFC PATCH 18/27] lift locking/unlocking ep->mtx out of ep_{start,done}_scan() Al Viro
2020-10-04  2:39   ` [RFC PATCH 19/27] ep_insert(): don't open-code ep_remove() on failure exits Al Viro
2020-10-04  2:39   ` [RFC PATCH 20/27] ep_insert(): we only need tep->mtx around the insertion itself Al Viro
2020-10-04 12:56     ` [ep_insert()] 9ee1cc5666: WARNING:possible_recursive_locking_detected kernel test robot
2020-10-04 14:17       ` Al Viro
2020-10-04 14:27         ` Al Viro
2020-10-04  2:39   ` [RFC PATCH 21/27] take the common part of ep_eventpoll_poll() and ep_item_poll() into helper Al Viro
2020-10-04  2:39   ` [RFC PATCH 22/27] fold ep_read_events_proc() into the only caller Al Viro
2020-10-04  2:39   ` [RFC PATCH 23/27] ep_insert(): move creation of wakeup source past the fl_ep_links insertion Al Viro
2020-10-04  2:39   ` [RFC PATCH 24/27] convert ->f_ep_links/->fllink to hlist Al Viro
2020-10-04  2:39   ` [RFC PATCH 25/27] lift rcu_read_lock() into reverse_path_check() Al Viro
2020-10-04  2:39   ` [RFC PATCH 26/27] epoll: massage the check list insertion Al Viro
2020-10-04  2:39   ` [RFC PATCH 27/27] epoll: take epitem list out of struct file Al Viro
2020-10-05 20:37     ` Qian Cai
2020-10-05 20:49       ` Al Viro
2020-10-04  2:49 ` [RFC][PATCHSET] epoll cleanups Al Viro
2020-10-04 12:13 ` Matthew Wilcox
2020-10-04 14:15   ` Al Viro
2020-10-04 18:08 ` Linus Torvalds
2020-10-04 20:05   ` Al Viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201004023929.2740074-7-viro@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).