Skip to contentSkip to conversation

fget: Do not loop with rcu lock held

PATCH In review Sergey Temerkhanov 3 participants 3 messages Dec 15, 2020 – Dec 16, 2020 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fget: Do not loop with rcu lock held

Unlock RCU before running another loop iteration

---
 fs/file.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)
fs/file.c +20 -14
index 4559b5fec3bd..49d57752e7a6 100644
@@ -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;
 }
Signature · 1 line
2.25.1
#1 lore raw
Quoted 1 line · Sergey Temerkhanov

Unlock RCU before running another loop iteration

Why?

maintainer
#2 lore raw
In reply to Sergey Temerkhanov
Quoted 1 line · Sergey Temerkhanov

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.