lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250129181800.ADD26AB5@davehans-spike.ostc.intel.com>
Date: Wed, 29 Jan 2025 10:18:00 -0800
From: Dave Hansen <dave.hansen@...ux.intel.com>
To: linux-kernel@...r.kernel.org
Cc: Linus Torvalds <torvalds@...ux-foundation.org>,Ted Ts'o <tytso@....edu>,Christian Brauner <brauner@...nel.org>,Darrick J. Wong <djwong@...nel.org>,Matthew Wilcox (Oracle) <willy@...radead.org>,Al Viro <viro@...iv.linux.org.uk>,linux-fsdevel@...r.kernel.org,Dave Hansen <dave.hansen@...ux.intel.com>,clm@...com,josef@...icpanda.com,dsterba@...e.com,linux-btrfs@...r.kernel.org
Subject: [PATCH 6/7] btrfs: Move prefaulting out of hot write path


From: Dave Hansen <dave.hansen@...ux.intel.com>

Prefaulting the write source buffer incurs an extra userspace access
in the common fast path. Make btrfs_buffered_write() consistent with
generic_perform_write(): only touch userspace an extra time when
copy_folio_from_iter_atomic() has failed to make progress.

Signed-off-by: Dave Hansen <dave.hansen@...ux.intel.com>
Cc: Chris Mason <clm@...com>
Cc: Josef Bacik <josef@...icpanda.com>
Cc: David Sterba <dsterba@...e.com>
Cc: linux-btrfs@...r.kernel.org
---

 b/fs/btrfs/file.c |   20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff -puN fs/btrfs/file.c~btrfs-postfault fs/btrfs/file.c
--- a/fs/btrfs/file.c~btrfs-postfault	2025-01-29 09:03:36.927756510 -0800
+++ b/fs/btrfs/file.c	2025-01-29 09:03:36.935757176 -0800
@@ -1164,15 +1164,6 @@ ssize_t btrfs_buffered_write(struct kioc
 		int extents_locked;
 		bool force_page_uptodate = false;
 
-		/*
-		 * Fault pages before locking them in prepare_one_folio()
-		 * to avoid recursive lock
-		 */
-		if (unlikely(fault_in_iov_iter_readable(i, write_bytes))) {
-			ret = -EFAULT;
-			break;
-		}
-
 		only_release_metadata = false;
 		sector_offset = pos & (fs_info->sectorsize - 1);
 
@@ -1314,6 +1305,17 @@ again:
 
 		cond_resched();
 
+		/*
+		 * Fault pages in a slow path after dropping folio
+		 * lock. This avoids the chance of deadlocking in
+		 * the fault handler.
+		 */
+		if (unlikely(copied == 0) &&
+		    (fault_in_iov_iter_readable(i, write_bytes) == write_bytes)) {
+			ret = -EFAULT;
+			break;
+		}
+
 		pos += copied;
 		num_written += copied;
 	}
_

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ