linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sergey Temerkhanov <s.temerkhanov@gmail.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Sergey Temerkhanov <s.temerkhanov@gmail.com>
Subject: [PATCH] fget: Do not loop with rcu lock held
Date: Tue, 15 Dec 2020 19:41:23 +0300	[thread overview]
Message-ID: <20201215164123.609980-1-s.temerkhanov@gmail.com> (raw)

Unlock RCU before running another loop iteration

Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com>
---
 fs/file.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/fs/file.c b/fs/file.c
index 4559b5fec3bd..49d57752e7a6 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -823,21 +823,27 @@ static struct file *__fget_files(struct files_struct *files, unsigned int fd,
 				 fmode_t mask, unsigned int refs)
 {
 	struct file *file;
+	bool again = false;
 
-	rcu_read_lock();
-loop:
-	file = fcheck_files(files, fd);
-	if (file) {
-		/* File object ref couldn't be taken.
-		 * dup2() atomicity guarantee is the reason
-		 * we loop to catch the new file (or NULL pointer)
-		 */
-		if (file->f_mode & mask)
-			file = NULL;
-		else if (!get_file_rcu_many(file, refs))
-			goto loop;
-	}
-	rcu_read_unlock();
+	do {
+		rcu_read_lock();
+
+		file = fcheck_files(files, fd);
+		if (file) {
+			/* File object ref couldn't be taken.
+			 * dup2() atomicity guarantee is the reason
+			 * we loop to catch the new file (or NULL pointer)
+			 */
+			if (file->f_mode & mask)
+				file = NULL;
+			else if (!get_file_rcu_many(file, refs))
+				again = true;
+		}
+		rcu_read_unlock();
+
+		if (unlikely(again))
+			schedule();
+	} while (again);
 
 	return file;
 }
-- 
2.25.1


             reply	other threads:[~2020-12-15 16:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-15 16:41 Sergey Temerkhanov [this message]
2020-12-15 17:13 ` [PATCH] fget: Do not loop with rcu lock held Matthew Wilcox
2020-12-16  2:47 ` 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=20201215164123.609980-1-s.temerkhanov@gmail.com \
    --to=s.temerkhanov@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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).