linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fget: Do not loop with rcu lock held
@ 2020-12-15 16:41 Sergey Temerkhanov
  2020-12-15 17:13 ` Matthew Wilcox
  2020-12-16  2:47 ` Al Viro
  0 siblings, 2 replies; 3+ messages in thread
From: Sergey Temerkhanov @ 2020-12-15 16:41 UTC (permalink / raw)
  To: Alexander Viro, linux-fsdevel, linux-kernel; +Cc: Sergey Temerkhanov

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] fget: Do not loop with rcu lock held
  2020-12-15 16:41 [PATCH] fget: Do not loop with rcu lock held Sergey Temerkhanov
@ 2020-12-15 17:13 ` Matthew Wilcox
  2020-12-16  2:47 ` Al Viro
  1 sibling, 0 replies; 3+ messages in thread
From: Matthew Wilcox @ 2020-12-15 17:13 UTC (permalink / raw)
  To: Sergey Temerkhanov; +Cc: Alexander Viro, linux-fsdevel, linux-kernel

On Tue, Dec 15, 2020 at 07:41:23PM +0300, Sergey Temerkhanov wrote:
> Unlock RCU before running another loop iteration

Why?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fget: Do not loop with rcu lock held
  2020-12-15 16:41 [PATCH] fget: Do not loop with rcu lock held Sergey Temerkhanov
  2020-12-15 17:13 ` Matthew Wilcox
@ 2020-12-16  2:47 ` Al Viro
  1 sibling, 0 replies; 3+ messages in thread
From: Al Viro @ 2020-12-16  2:47 UTC (permalink / raw)
  To: Sergey Temerkhanov; +Cc: linux-fsdevel, linux-kernel

On Tue, Dec 15, 2020 at 07:41:23PM +0300, Sergey Temerkhanov wrote:
> Unlock RCU before running another loop iteration

If you are able to keep it looping for a long time, I would really
like to see the reproducer.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-16  2:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-15 16:41 [PATCH] fget: Do not loop with rcu lock held Sergey Temerkhanov
2020-12-15 17:13 ` Matthew Wilcox
2020-12-16  2:47 ` Al Viro

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).