From patchwork Wed Jan 29 18:17:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 13954027 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0CD21E102D; Wed, 29 Jan 2025 18:17:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738174675; cv=none; b=UKaX6uGEdlCcLBoIx5fBoKi336gXX4HdhfBO+JdxYYXTnV3NMQ59XnGSRz2W84CylcMPGZwCui2gzCa3pfjCmlPhNuiKErC2b0HfSmjT3d3ISJc21y7BGmYXXBoGZe6v1AV70qy98UuQILKDAMkK4b7PBtCcy026v8494CsR8Eg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738174675; c=relaxed/simple; bh=4ZsGt+mSqlSAqYZrfKA4JnU6As4w0ZGKCAyoOMuu+Ww=; h=Subject:To:Cc:From:Date:References:In-Reply-To:Message-Id; b=tcoGbZCfV4XF7VFwu12BPZ8ue0+xHxslXFB8oszHLpWwr+Kwon21Buy1nZ7c6zc0pqv/unZWMMIbir6RWacsdDK2d794nzxhknt4PaFKyn+CTebfzfxNzT+ZUQ3fxMXlSLOSAbugEeQrlagDc0Q+XDktzCSMYmApg+E4aiKnc2o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Eb9Pd4iJ; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Eb9Pd4iJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1738174674; x=1769710674; h=subject:to:cc:from:date:references:in-reply-to: message-id; bh=4ZsGt+mSqlSAqYZrfKA4JnU6As4w0ZGKCAyoOMuu+Ww=; b=Eb9Pd4iJ/vVxYIQhpj4pQt4cOqCg7dGcuhyUeF1n2kagOJvvN4fuTg6U EH82A5O7YjHQ5oXIwD1xYEjhZtY2V+lX1a56KptFEDemBaA3IxVMa2Fd/ oit31t6ELj5TZfZOnsuW9E+jL6huhb8/b7uPlDcklxUd4+e/lnJiZCjUy HHoEbsWPwzzrhNoPcbJFJ3QVBgSvPjCU5xld1ZU4cacOud9n9RJMv32iJ MshAu9Ps3FiTpgxonCt4iKBeA2DplIv8Y/wZXwiZBAnOr7DsSX0obCNnB HQtKqutCiI0VR9atkitEkzUGrQsTOC9HQF6ezuAIdeFwRlqxqHg43Z71s A==; X-CSE-ConnectionGUID: 8HK/aiFtQBa3edxR7MKKGQ== X-CSE-MsgGUID: oZaCnLbXTiGN/YPs+Us+SQ== X-IronPort-AV: E=McAfee;i="6700,10204,11330"; a="38963252" X-IronPort-AV: E=Sophos;i="6.13,244,1732608000"; d="scan'208";a="38963252" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2025 10:17:52 -0800 X-CSE-ConnectionGUID: AfMh9vWrQWWq1Ktri4LMmw== X-CSE-MsgGUID: QEjHVrpySoGlcpXG0wmaTA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,244,1732608000"; d="scan'208";a="109660680" Received: from davehans-spike.ostc.intel.com (HELO localhost.localdomain) ([10.165.164.11]) by fmviesa010.fm.intel.com with ESMTP; 29 Jan 2025 10:17:51 -0800 Subject: [PATCH 1/7] filemap: Move prefaulting out of hot write path To: linux-kernel@vger.kernel.org Cc: Linus Torvalds ,Ted Ts'o ,Christian Brauner ,Darrick J. Wong ,Matthew Wilcox (Oracle) ,Al Viro ,linux-fsdevel@vger.kernel.org,Dave Hansen From: Dave Hansen Date: Wed, 29 Jan 2025 10:17:51 -0800 References: <20250129181749.C229F6F3@davehans-spike.ostc.intel.com> In-Reply-To: <20250129181749.C229F6F3@davehans-spike.ostc.intel.com> Message-Id: <20250129181751.5527308F@davehans-spike.ostc.intel.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: From: Dave Hansen There is a bit of a sordid history here. I originally wrote 998ef75ddb57 ("fs: do not prefault sys_write() user buffer pages") to fix a performance issue that showed up on early SMAP hardware. But that was reverted with 00a3d660cbac because it exposed an underlying filesystem bug. This is a reimplementation of the original commit along with some simplification and comment improvements. The basic problem is that the generic write path has two userspace accesses: one to prefault the write source buffer and then another to perform the actual write. On x86, this means an extra STAC/CLAC pair. These are relatively expensive instructions because they function as barriers. Keep the prefaulting behavior but move it into the slow path that gets run when the write did not make any progress. This avoids livelocks that can happen when the write's source and destination target the same folio. Contrary to the existing comments, the fault-in does not prevent deadlocks. That's accomplished by using an "atomic" usercopy that disables page faults. The end result is that the generic write fast path now touches userspace once instead of twice. That should speed things up. Signed-off-by: Dave Hansen Link: https://lore.kernel.org/all/yxyuijjfd6yknryji2q64j3keq2ygw6ca6fs5jwyolklzvo45s@4u63qqqyosy2/ Cc: Ted Ts'o --- b/mm/filemap.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff -puN mm/filemap.c~generic_perform_write-1 mm/filemap.c --- a/mm/filemap.c~generic_perform_write-1 2025-01-29 09:03:30.963260106 -0800 +++ b/mm/filemap.c 2025-01-29 09:03:30.971260772 -0800 @@ -4027,17 +4027,6 @@ retry: bytes = min(chunk - offset, bytes); balance_dirty_pages_ratelimited(mapping); - /* - * Bring in the user page that we will copy from _first_. - * Otherwise there's a nasty deadlock on copying from the - * same page as we're writing to, without it being marked - * up-to-date. - */ - if (unlikely(fault_in_iov_iter_readable(i, bytes) == bytes)) { - status = -EFAULT; - break; - } - if (fatal_signal_pending(current)) { status = -EINTR; break; @@ -4055,6 +4044,11 @@ retry: if (mapping_writably_mapped(mapping)) flush_dcache_folio(folio); + /* + * This needs to be atomic because actually handling page + * faults on 'i' can deadlock if the copy targets a + * userspace mapping of 'folio'. + */ copied = copy_folio_from_iter_atomic(folio, offset, bytes, i); flush_dcache_folio(folio); @@ -4080,6 +4074,16 @@ retry: bytes = copied; goto retry; } + + /* + * 'folio' is now unlocked and faults on it can be + * handled. Ensure forward progress by trying to + * fault it in now. + */ + if (fault_in_iov_iter_readable(i, bytes) == bytes) { + status = -EFAULT; + break; + } } else { pos += status; written += status; From patchwork Wed Jan 29 18:17:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 13954028 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CAF71E231D; Wed, 29 Jan 2025 18:17:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738174676; cv=none; b=KjZv1lDFjiP2dkj5eBn+oC8wlmy7S9vCDhryMw2XjtWz0VEp3xM2nxWk4a1G+MLsE6Is1GXjEbgNfF1Iul9MxIRwdAifQe5Ilk255DCntStiKr7jbTSwQd75WYgEBX8sGSp0K1n/0z5yOdA+SwiAkj5qQ1tRe+V73FTUG8dlbdE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738174676; c=relaxed/simple; bh=Hk50vFeQpYvObpB97CiiwSn4PpFmEbUPkBXYfgNIvTs=; h=Subject:To:Cc:From:Date:References:In-Reply-To:Message-Id; b=s7PSnmzwXtSJyl/sMu5frmcTScrIhqvQrHKeh1FXQviQNuxvZMbTmKnUOdBXsryMhrjSA1shJ9hS2FJsp+wTKTJUW9x7LpKZbZYVQ8wS89qXeySlwvs9t5F8xk7V34zao1xOSaNutupoeW0IQvXYJ+j9AI70t+yEBGRxKcMuWqQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=QXa+/qWQ; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QXa+/qWQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1738174675; x=1769710675; h=subject:to:cc:from:date:references:in-reply-to: message-id; bh=Hk50vFeQpYvObpB97CiiwSn4PpFmEbUPkBXYfgNIvTs=; b=QXa+/qWQYsn4rZ/tA8KKdVtuSJc9Yq8BxC+kUt3Hf5ct9s/658Y8Rlig cSILHzBP9PsfIhzrYiyDdKcfUBjZaEI9VFYb84FZauXpw4/mpLXih7uOR 9Yp5X73I8AlIQa3SfRkmeArx2zuNP3Zou3WmjwK+qTNZREm9vcm+Uumgp V79YdOpMp2QQ/GBt2IQ5UN5amxz9R9rTfS/tv63KD41CLy8cTVr66bVnt eoo84ry3deDN7RyItmcg+jkzs/AT+d7z8xC1DaulS4mfu6oRLUezj8w7N 8RB6z7lUfFrh3smCKvRUzEDNqXuYMKt3HB9P0bYHovlAL7DX3INfvBKOs Q==; X-CSE-ConnectionGUID: h2GXtnxBRZy1IxIlRUc1uQ== X-CSE-MsgGUID: nrfLazYMRiCkcmVEt/Wuxg== X-IronPort-AV: E=McAfee;i="6700,10204,11330"; a="38963260" X-IronPort-AV: E=Sophos;i="6.13,244,1732608000"; d="scan'208";a="38963260" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2025 10:17:54 -0800 X-CSE-ConnectionGUID: HC18c4gKT0mRme/zoCGBCw== X-CSE-MsgGUID: XSURPr9BTAOZvctmvN1GRA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,244,1732608000"; d="scan'208";a="109660686" Received: from davehans-spike.ostc.intel.com (HELO localhost.localdomain) ([10.165.164.11]) by fmviesa010.fm.intel.com with ESMTP; 29 Jan 2025 10:17:53 -0800 Subject: [PATCH 2/7] iomap: Move prefaulting out of hot write path To: linux-kernel@vger.kernel.org Cc: Linus Torvalds ,Ted Ts'o ,Christian Brauner ,Darrick J. Wong ,Matthew Wilcox (Oracle) ,Al Viro ,linux-fsdevel@vger.kernel.org,Dave Hansen ,linux-xfs@vger.kernel.org From: Dave Hansen Date: Wed, 29 Jan 2025 10:17:53 -0800 References: <20250129181749.C229F6F3@davehans-spike.ostc.intel.com> In-Reply-To: <20250129181749.C229F6F3@davehans-spike.ostc.intel.com> Message-Id: <20250129181753.3927F212@davehans-spike.ostc.intel.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: From: Dave Hansen Prefaulting the write source buffer incurs an extra userspace access in the common fast path. Make iomap_write_iter() 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 Cc: Christian Brauner Cc: "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org --- b/fs/iomap/buffered-io.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff -puN fs/iomap/buffered-io.c~iomap-postfault fs/iomap/buffered-io.c --- a/fs/iomap/buffered-io.c~iomap-postfault 2025-01-29 09:03:32.179361299 -0800 +++ b/fs/iomap/buffered-io.c 2025-01-29 09:03:32.187361965 -0800 @@ -937,21 +937,6 @@ retry: if (bytes > length) bytes = length; - /* - * Bring in the user page that we'll copy from _first_. - * Otherwise there's a nasty deadlock on copying from the - * same page as we're writing to, without it being marked - * up-to-date. - * - * For async buffered writes the assumption is that the user - * page has already been faulted in. This can be optimized by - * faulting the user page. - */ - if (unlikely(fault_in_iov_iter_readable(i, bytes) == bytes)) { - status = -EFAULT; - break; - } - status = iomap_write_begin(iter, pos, bytes, &folio); if (unlikely(status)) { iomap_write_failed(iter->inode, pos, bytes); @@ -1005,6 +990,15 @@ retry: bytes = copied; goto retry; } + /* + * 'folio' is now unlocked and faults on it can be + * handled. Ensure forward progress by trying to + * fault it in now. + */ + if (fault_in_iov_iter_readable(i, bytes) == bytes) { + status = -EFAULT; + break; + } } else { pos += written; total_written += written; From patchwork Wed Jan 29 18:17:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 13954029 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC4261E3769; Wed, 29 Jan 2025 18:17:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738174677; cv=none; b=RFa0WvxFX1YWqW3Ud1i0YvsCm73wvLp7xIxhdWJp+qZGGr/uwesMDNTuTUwcJv0x/vY4TFAd8XPnRaWTPYoypoNvdtqCbfc1n2O/aAuhQdMwPaYZweuHFDDcJZyq+gPhl9/1vvnygAFDNVgx+ohhjM82p1MVswf1Z4fsyJwL6OA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738174677; c=relaxed/simple; bh=Paf3+ijHUFNtyyN6KcdjzOxLl545G89WBoHPMc/pbAs=; h=Subject:To:Cc:From:Date:References:In-Reply-To:Message-Id; b=sEsrWdemXg2HIknHRW9dEsTUmeBJDDBvgGIuESIZx6eCL77ZMkS7KPO6Cqt+aKU978OlT74tNx2fWj86mKox8q6nkqyn/z0coM195VHezI1GDMt3Sn+sYw/7qxtAHN7fv/iatcMLYavjCedcOfrNYLQ/Krg+hhgD3O15x0v+0R4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=KdSHKhWm; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="KdSHKhWm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1738174676; x=1769710676; h=subject:to:cc:from:date:references:in-reply-to: message-id; bh=Paf3+ijHUFNtyyN6KcdjzOxLl545G89WBoHPMc/pbAs=; b=KdSHKhWm2sVi24l0cEuXjMJZyZvpi6lTA8n+a6RNtlfqgRcNEEyGbpPh YRowIxhMjKCNpyJ8ra6ZDZ/D7wd/bslQpE9jwYGFOkavbhbR9MKTUbX43 KcQqqJJ3a3SJUhIUZLTeCEeoPQf4hz6sh+NUNhADsCYwLuVBObzPsCZx9 Ksgjx5G1kn46jDW7fQycPrfpN7T+u0JRSs+aRl3tR9l1OXlT778Lw8WsQ 8vCmVlx0CWJUOO3tmfX+sULSKqYnTRKiRtYsP+BDJOj3WHE3UbUs5KNFB ZKJUeDOXQWGt3UU/GtF8/+FA8ijhEY5S9YXiQcRka/6/P7HuSPRRkJpLB A==; X-CSE-ConnectionGUID: IG9ODW5ORSGqepnpkwk8/Q== X-CSE-MsgGUID: 8KtEdrwwS2WgPXHljg4kUw== X-IronPort-AV: E=McAfee;i="6700,10204,11330"; a="38963271" X-IronPort-AV: E=Sophos;i="6.13,244,1732608000"; d="scan'208";a="38963271" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2025 10:17:56 -0800 X-CSE-ConnectionGUID: SdZhgKGNSWS0IVbLVlNSDA== X-CSE-MsgGUID: u1NfJiPzS/eThxPMpekFDw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,244,1732608000"; d="scan'208";a="109660692" Received: from davehans-spike.ostc.intel.com (HELO localhost.localdomain) ([10.165.164.11]) by fmviesa010.fm.intel.com with ESMTP; 29 Jan 2025 10:17:55 -0800 Subject: [PATCH 3/7] ntfs3: Move prefaulting out of hot write path To: linux-kernel@vger.kernel.org Cc: Linus Torvalds ,Ted Ts'o ,Christian Brauner ,Darrick J. Wong ,Matthew Wilcox (Oracle) ,Al Viro ,linux-fsdevel@vger.kernel.org,Dave Hansen ,almaz.alexandrovich@paragon-software.com,ntfs3@lists.linux.dev From: Dave Hansen Date: Wed, 29 Jan 2025 10:17:55 -0800 References: <20250129181749.C229F6F3@davehans-spike.ostc.intel.com> In-Reply-To: <20250129181749.C229F6F3@davehans-spike.ostc.intel.com> Message-Id: <20250129181755.D845753B@davehans-spike.ostc.intel.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: From: Dave Hansen Prefaulting the write source buffer incurs an extra userspace access in the common fast path. Make ntfs_compress_write() consistent with generic_perform_write(): only touch userspace an extra time when copy_page_from_iter_atomic() has failed to make progress. Signed-off-by: Dave Hansen Cc: Konstantin Komarov Cc: ntfs3@lists.linux.dev --- b/fs/ntfs3/file.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff -puN fs/ntfs3/file.c~ntfs-postfault fs/ntfs3/file.c --- a/fs/ntfs3/file.c~ntfs-postfault 2025-01-29 09:03:33.371460504 -0800 +++ b/fs/ntfs3/file.c 2025-01-29 09:03:33.375460837 -0800 @@ -1092,11 +1092,6 @@ static ssize_t ntfs_compress_write(struc frame_vbo = pos & ~(frame_size - 1); index = frame_vbo >> PAGE_SHIFT; - if (unlikely(fault_in_iov_iter_readable(from, bytes))) { - err = -EFAULT; - goto out; - } - /* Load full frame. */ err = ntfs_get_frame_pages(mapping, index, pages, pages_per_frame, &frame_uptodate); @@ -1172,6 +1167,18 @@ static ssize_t ntfs_compress_write(struc */ cond_resched(); + if (unlikely(!copied)) { + /* + * folios are now unlocked and faults on them can be + * handled. Ensure forward progress by trying to + * fault in 'from' in case it maps one of the folios. + */ + if (fault_in_iov_iter_readable(from, bytes)) { + err = -EFAULT; + goto out; + } + } + pos += copied; written += copied; From patchwork Wed Jan 29 18:17:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 13954030 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1AAAF1E5714; Wed, 29 Jan 2025 18:17:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738174679; cv=none; b=IzHGZXrH5kZfczSLzWZdgcHmBay4KaEtB288EIzGjlAbKvV6QVsieSXj1RvGkRWY2gHIzhSpUao153FpTW6kC6IMXi3bxK86qFwxM5xHX71SSfOlFJCNv5QaBQbwX6+nrIeuMh1VpB7k2zr2GZ8NEnGCwqI97iBY7b8VNbTNHxg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738174679; c=relaxed/simple; bh=ZB1S1SiyH/U7od1QypPsMdpBO9FAAMDntVuVsY0yEUA=; h=Subject:To:Cc:From:Date:References:In-Reply-To:Message-Id; b=HvS7HSnLbLPsf99XNe6DYkqFEh/qppcprCrkM1Pg/lEM0suys1DAQNZfLtJfOjHIfsaNV7hEix7zpFw8pZKPrF5ueWmA8fp+vXo8/P2KaXPsQuVkOAqGzoclZ14netOptHQm5SOuiNVU7Y73S3M2guerqo3/Xic8Y/cXWmQQ04Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Rh0mfakG; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Rh0mfakG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1738174678; x=1769710678; h=subject:to:cc:from:date:references:in-reply-to: message-id; bh=ZB1S1SiyH/U7od1QypPsMdpBO9FAAMDntVuVsY0yEUA=; b=Rh0mfakGvpilO828H34QeflaT849kchi/bQLR49cGOy5KuuaOzMrI8G7 95X1+/y4WuJGkTrxTkarr8onvW56Ot8PmyzeLooNZWwTOCGjTXrDiKPfD s80piaF2xj63PZuAV7tdVbiaDvF3oflsouK3xIqPXTlAR+b0uAxCcRFnk WxVwjdWpdXcIWKPfxvI5Fk4iZlHIEAwPLVy1Vg96vhnRcvMT734S4O3+n /pG9A6hPYA1mA2FAbmBKqhLUCE6SPWSD5Fqy23/3qI0pNcZTO5FCUrMSJ yrv98cn4k1vUynm9/wqXIcFTh7FdhEVC/+kHBP9xyrSC35raxTa63DblM w==; X-CSE-ConnectionGUID: ck3zQTxsSrOww0uQpsj29g== X-CSE-MsgGUID: ILF4TMggRYGsNSWgKtB4Fw== X-IronPort-AV: E=McAfee;i="6700,10204,11330"; a="38963280" X-IronPort-AV: E=Sophos;i="6.13,244,1732608000"; d="scan'208";a="38963280" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2025 10:17:58 -0800 X-CSE-ConnectionGUID: yOkUViQpTzuW2zKP0RUutg== X-CSE-MsgGUID: /MDk59v4REuZdJJqDwVRNA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,244,1732608000"; d="scan'208";a="109660696" Received: from davehans-spike.ostc.intel.com (HELO localhost.localdomain) ([10.165.164.11]) by fmviesa010.fm.intel.com with ESMTP; 29 Jan 2025 10:17:57 -0800 Subject: [PATCH 4/7] fuse: Move prefaulting out of hot write path To: linux-kernel@vger.kernel.org Cc: Linus Torvalds ,Ted Ts'o ,Christian Brauner ,Darrick J. Wong ,Matthew Wilcox (Oracle) ,Al Viro ,linux-fsdevel@vger.kernel.org,Dave Hansen ,miklos@szeredi.hu From: Dave Hansen Date: Wed, 29 Jan 2025 10:17:56 -0800 References: <20250129181749.C229F6F3@davehans-spike.ostc.intel.com> In-Reply-To: <20250129181749.C229F6F3@davehans-spike.ostc.intel.com> Message-Id: <20250129181756.44C9597C@davehans-spike.ostc.intel.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: From: Dave Hansen Prefaulting the write source buffer incurs an extra userspace access in the common fast path. Make fuse_fill_write_pages() 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 Cc: Miklos Szeredi --- b/fs/fuse/file.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff -puN fs/fuse/file.c~fuse-postfault fs/fuse/file.c --- a/fs/fuse/file.c~fuse-postfault 2025-01-29 09:03:34.515555724 -0800 +++ b/fs/fuse/file.c 2025-01-29 09:03:34.523556390 -0800 @@ -1234,10 +1234,6 @@ static ssize_t fuse_fill_write_pages(str bytes = min_t(size_t, bytes, fc->max_write - count); again: - err = -EFAULT; - if (fault_in_iov_iter_readable(ii, bytes)) - break; - folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN, mapping_gfp_mask(mapping)); if (IS_ERR(folio)) { @@ -1254,6 +1250,16 @@ static ssize_t fuse_fill_write_pages(str if (!tmp) { folio_unlock(folio); folio_put(folio); + + /* + * Ensure forward progress by faulting in + * while not holding the folio lock: + */ + if (fault_in_iov_iter_readable(ii, bytes)) { + err = -EFAULT; + break; + } + goto again; } From patchwork Wed Jan 29 18:17:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 13954031 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CEA171E8855; Wed, 29 Jan 2025 18:17:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738174681; cv=none; b=DGWaAETRcapvrAelzq92afPQj+9a6BuLJuEj6zY8IbSlCFhLlENxBUGNH8kYCAzyO81UIq/tnUocPS2s55GHnm/6AYFUT4bIVeSfKbyol7zWkk3UQUcZ2FIYXtzoY1Qgsns5T0Q2DjHvphP7wZ9wN8Ij/H5TlKXhTO4PnytcTGA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738174681; c=relaxed/simple; bh=nLgUtcYlqdDJ5L2EieCeuBPNfu+z4xGNGz6lMKw+vhI=; h=Subject:To:Cc:From:Date:References:In-Reply-To:Message-Id; b=HPOhkZp/qxhzFuZdwN0RFeIX7aVTp6VL2HpxGum0S8rP9IVmnP2ZWDA4uSdaTbXyKVnDSoQWOzCgAbIIQ00UvWG67tjDGco6RhIifoEMX66TGA7iwDxdaAv+ORNgpey0ysNSUt1ktmTniBYlmjogMlkEO3IBiULDEluq8M9T9Cs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=jUhLux2X; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jUhLux2X" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1738174680; x=1769710680; h=subject:to:cc:from:date:references:in-reply-to: message-id; bh=nLgUtcYlqdDJ5L2EieCeuBPNfu+z4xGNGz6lMKw+vhI=; b=jUhLux2XfWhfo90mEciO9N4dggPL8lpinS7Zt0jl2zBZVkdtvLM8QzXH v7F/6fxuQGUJoSSDxdloyF+mc6wOe8Px9pEWeZ++idKBh94cKjiTUFxfI a4smpDovqZdrp05lEP7Y851QsflY1W6WLVpyrBXfLAZSIQj1XxtoJIfCb 4BL+3iuMXy6PzyITloDvKJs+ZMvmEmDc5doBSGoRnQylan/4rHY75fTSe NQeQ7mAXjXPn3NpISRkm5LnSBpwLpuEdSWtnVtnvC8vsFZJOunX8RYhbZ TBNiCUXmD5eevrYrvlgksRsY/OIBUXmtGN+/CSISJhwl3z6qOAgnaBfjg w==; X-CSE-ConnectionGUID: RmREMfmEQFyzjvg7REueAA== X-CSE-MsgGUID: 2l0b5Ba6SQmVsbqznEP+RQ== X-IronPort-AV: E=McAfee;i="6700,10204,11330"; a="38963290" X-IronPort-AV: E=Sophos;i="6.13,244,1732608000"; d="scan'208";a="38963290" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2025 10:17:59 -0800 X-CSE-ConnectionGUID: ww5Xh3pdR/irjie2ZpJdIw== X-CSE-MsgGUID: PdOV2w8hTjaNsIKdStEJNg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,244,1732608000"; d="scan'208";a="109660700" Received: from davehans-spike.ostc.intel.com (HELO localhost.localdomain) ([10.165.164.11]) by fmviesa010.fm.intel.com with ESMTP; 29 Jan 2025 10:17:58 -0800 Subject: [PATCH 5/7] bcachefs: Move prefaulting out of hot write path To: linux-kernel@vger.kernel.org Cc: Linus Torvalds ,Ted Ts'o ,Christian Brauner ,Darrick J. Wong ,Matthew Wilcox (Oracle) ,Al Viro ,linux-fsdevel@vger.kernel.org,Dave Hansen ,kent.overstreet@linux.dev,linux-bcachefs@vger.kernel.org From: Dave Hansen Date: Wed, 29 Jan 2025 10:17:58 -0800 References: <20250129181749.C229F6F3@davehans-spike.ostc.intel.com> In-Reply-To: <20250129181749.C229F6F3@davehans-spike.ostc.intel.com> Message-Id: <20250129181758.ACB89DF8@davehans-spike.ostc.intel.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: From: Dave Hansen Prefaulting the write source buffer incurs an extra userspace access in the common fast path. Make bch2_buffered_write() consistent with generic_perform_write(): only touch userspace an extra time when copy_page_from_iter_atomic() has failed to make progress. This also zaps a comment. It referred to a possible deadlock and to userspace address checks. Neither of those things are a concern when using copy_folio_from_iter_atomic() for atomic usercopies. It prevents deadlocks by disabling page faults and it leverages user copy functions that have their own access_ok() checks. Signed-off-by: Dave Hansen Cc: Kent Overstreet Cc: linux-bcachefs@vger.kernel.org --- b/fs/bcachefs/fs-io-buffered.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff -puN fs/bcachefs/fs-io-buffered.c~bcachefs-postfault fs/bcachefs/fs-io-buffered.c --- a/fs/bcachefs/fs-io-buffered.c~bcachefs-postfault 2025-01-29 09:03:35.727656612 -0800 +++ b/fs/bcachefs/fs-io-buffered.c 2025-01-29 09:03:35.731656945 -0800 @@ -970,26 +970,6 @@ static ssize_t bch2_buffered_write(struc unsigned offset = pos & (PAGE_SIZE - 1); unsigned bytes = iov_iter_count(iter); again: - /* - * Bring in the user page that we will copy from _first_. - * Otherwise there's a nasty deadlock on copying from the - * same page as we're writing to, without it being marked - * up-to-date. - * - * Not only is this an optimisation, but it is also required - * to check that the address is actually valid, when atomic - * usercopies are used, below. - */ - if (unlikely(fault_in_iov_iter_readable(iter, bytes))) { - bytes = min_t(unsigned long, iov_iter_count(iter), - PAGE_SIZE - offset); - - if (unlikely(fault_in_iov_iter_readable(iter, bytes))) { - ret = -EFAULT; - break; - } - } - if (unlikely(fatal_signal_pending(current))) { ret = -EINTR; break; @@ -1012,6 +992,16 @@ again: */ bytes = min_t(unsigned long, PAGE_SIZE - offset, iov_iter_single_seg_count(iter)); + + /* + * Faulting in 'iter' may be required for forward + * progress. Do it here, out outside the fast path + * and when not holding any folio locks. + */ + if (fault_in_iov_iter_readable(iter, bytes) == bytes) { + ret = -EFAULT; + break; + } goto again; } pos += ret; From patchwork Wed Jan 29 18:18:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 13954032 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 549211E9B06; Wed, 29 Jan 2025 18:18:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738174682; cv=none; b=luHg/v1PpCtESBH/cAfEGzR1EKBEidSeKesWgpq+ES4ohy+qxMGV+I0GzdvSQZq90yE6QAol5tJEKc9cZb8M2CU2XZ+aQc/g+we04o2F4NuIBEhoqKaWX5WehaUed17JrNeSChiDPrdf6KBqT0K9h72lFq/1fO6m6AL3JrE0s0Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738174682; c=relaxed/simple; bh=ukQZNAO8hWvIF2SoL2m9NYJM3TAt2Q5qsnN0OoflgdY=; h=Subject:To:Cc:From:Date:References:In-Reply-To:Message-Id; b=HBf1Jazk05yHuSJT0o7DStTqGYa3z2aA5BJRMKjS2nIV6iI9tu89VE9zq5eMDmC2QEDKV2qMI4buWhWAeAkXrIFup7bmAyLOGLtXGxztv8oKuzD3XPOLB3ttR5q9CSS5p8x2ecnvqeDsqwObCxxg243TCAEcnuiPU2G9VmDgGYw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=jCVekLBU; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jCVekLBU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1738174682; x=1769710682; h=subject:to:cc:from:date:references:in-reply-to: message-id; bh=ukQZNAO8hWvIF2SoL2m9NYJM3TAt2Q5qsnN0OoflgdY=; b=jCVekLBUyXn9BgRQ3mhCo7Vzvpoy1E8/IRZfEEM9z6bZkZBrZX4NnNr2 WnIfR+FsI5Onojb3x6d4oaLUMRBDc6cF6EPMgbK8YMzaEweUFbQsQcr4/ t41HFUW5yzTG+bcIdh2JAa77L+brrZ04mG70YYjyqVk/NWH0VGbOHEr/L HSxkWFyjSqJmsbJrPXk0XSvE7VyiCSxERDkkvN79VPiIABPKyUCrlCM5Z xbkoiV+ytnHDqYGH9v7QsgmRSHqMr6WE5Q4S+IvhKIAV30DBS5rOqZqW4 W90L8R+z66Ijyb814BVYtcMzp8Ofxv8Zi3jNNX2cyE6qr+zrhfGw5akrp w==; X-CSE-ConnectionGUID: AkHdJNWRSKqUb2BIttlBiA== X-CSE-MsgGUID: gxBI1l+MRfqx+6kogdwpgg== X-IronPort-AV: E=McAfee;i="6700,10204,11330"; a="38963301" X-IronPort-AV: E=Sophos;i="6.13,244,1732608000"; d="scan'208";a="38963301" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2025 10:18:01 -0800 X-CSE-ConnectionGUID: sF2snHVmRsS0zc8iAi9uMw== X-CSE-MsgGUID: qBudLyCSRzexcU+0aByGXw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,244,1732608000"; d="scan'208";a="109660711" Received: from davehans-spike.ostc.intel.com (HELO localhost.localdomain) ([10.165.164.11]) by fmviesa010.fm.intel.com with ESMTP; 29 Jan 2025 10:18:00 -0800 Subject: [PATCH 6/7] btrfs: Move prefaulting out of hot write path To: linux-kernel@vger.kernel.org Cc: Linus Torvalds ,Ted Ts'o ,Christian Brauner ,Darrick J. Wong ,Matthew Wilcox (Oracle) ,Al Viro ,linux-fsdevel@vger.kernel.org,Dave Hansen ,clm@fb.com,josef@toxicpanda.com,dsterba@suse.com,linux-btrfs@vger.kernel.org From: Dave Hansen Date: Wed, 29 Jan 2025 10:18:00 -0800 References: <20250129181749.C229F6F3@davehans-spike.ostc.intel.com> In-Reply-To: <20250129181749.C229F6F3@davehans-spike.ostc.intel.com> Message-Id: <20250129181800.ADD26AB5@davehans-spike.ostc.intel.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: From: Dave Hansen 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 Cc: Chris Mason Cc: Josef Bacik Cc: David Sterba Cc: linux-btrfs@vger.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; } From patchwork Wed Jan 29 18:18:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 13954033 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB7531EBA05; Wed, 29 Jan 2025 18:18:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738174685; cv=none; b=lWRSvmIFXQMz8N1ggJbWoseAOonJu6rYSO3MEQ9O4EVpkXv0msX4UUXf1AHGdH4bfp56Fo74d4ZCcB9VFzkFBZDYTWbm18FG7zAs6od+34S2Yg3U7yZe0lymgajlgGLvLehLR/11Lj08b9O5TfcyOKO2lDxOJLO5vUnp9nbhX6U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738174685; c=relaxed/simple; bh=9HMpAKh/G4dXrhwsbs3yhGRxyGR4nQmn1BXXS8DWYsE=; h=Subject:To:Cc:From:Date:References:In-Reply-To:Message-Id; b=MlSIpcmmcmwFAzAstpcDH0rnczEIC2bStu4J2jKKOHZSjlbrIPxkZbg2b4rANamZBzA2J0BS0YAQ6j5LGhkKE36OWtYrsWFcLizitnYtGlk5Iz9lIhme7NZ5niKKypIpuoZlECKXH52IQPTluAcqhjQEaSi3oyj0q/LT4d1HAjU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=TnMaWOHx; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="TnMaWOHx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1738174684; x=1769710684; h=subject:to:cc:from:date:references:in-reply-to: message-id; bh=9HMpAKh/G4dXrhwsbs3yhGRxyGR4nQmn1BXXS8DWYsE=; b=TnMaWOHxyAe4ENoSZvC+i6KPCsti1e1nS6DP5xZE9Oe0ymbqcBIubzFY 9x6TFS8Tvf6pe/2NJmpMkrGjeWPsjn0UsFvHyehdLU73MF5xdThHLX4D9 sybgieatb4S+JJ126pc6LGc/G/z6wMCL3vyhBhIKs0CZeJBk4rCrQUlty gYMNkAncfxShlqYDIlAZj9HwGLrFv2f+EoZ+BX24iCwEbH3fHoLMoNsXB dWayiqLmJRFs/vdAHlfCrTJjtYWEz1NhCxTbaW9+jkXNG9op4qKP+tluV xVq3lNfXBnQznhif6OXGqGH79MvVbCNAxOGyCEI1h43rxXcwQesY7sWkw Q==; X-CSE-ConnectionGUID: YIYHpa4gQPm94xF5loQhjg== X-CSE-MsgGUID: fw1m8w2nSAeiAaJ6CZ/WXQ== X-IronPort-AV: E=McAfee;i="6700,10204,11330"; a="38963322" X-IronPort-AV: E=Sophos;i="6.13,244,1732608000"; d="scan'208";a="38963322" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2025 10:18:03 -0800 X-CSE-ConnectionGUID: hsjZ6/uvRziZN2sfKstoGg== X-CSE-MsgGUID: l/QrJ4vaTxCyPyjoeQ16lQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,244,1732608000"; d="scan'208";a="109660718" Received: from davehans-spike.ostc.intel.com (HELO localhost.localdomain) ([10.165.164.11]) by fmviesa010.fm.intel.com with ESMTP; 29 Jan 2025 10:18:02 -0800 Subject: [PATCH 7/7] netfs: Remove outdated comments about prefaulting To: linux-kernel@vger.kernel.org Cc: Linus Torvalds ,Ted Ts'o ,Christian Brauner ,Darrick J. Wong ,Matthew Wilcox (Oracle) ,Al Viro ,linux-fsdevel@vger.kernel.org,Dave Hansen ,dhowells@redhat.com,jlayton@kernel.org,netfs@lists.linux.dev From: Dave Hansen Date: Wed, 29 Jan 2025 10:18:02 -0800 References: <20250129181749.C229F6F3@davehans-spike.ostc.intel.com> In-Reply-To: <20250129181749.C229F6F3@davehans-spike.ostc.intel.com> Message-Id: <20250129181802.6E1E4149@davehans-spike.ostc.intel.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: From: Dave Hansen I originally set out to make netfs_perform_write() behavior more consistent with generic_perform_write(). However, netfs currently treats a failure to make forward progress as a hard error and does not retry where the generic code will loop around and retry. Instead of a major code restructuring, just focus on improving the comments. The comment refers to a possible deadlock and to userspace address checks. Neither of those things are a concern when using copy_folio_from_iter_atomic() for atomic usercopies. It prevents deadlocks by disabling page faults and it leverages user copy functions that have their own access_ok() checks. Signed-off-by: Dave Hansen Cc: David Howells Cc: Jeff Layton Cc: netfs@lists.linux.dev --- b/fs/netfs/buffered_write.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff -puN fs/netfs/buffered_write.c~netfs-postfault fs/netfs/buffered_write.c --- a/fs/netfs/buffered_write.c~netfs-postfault 2025-01-29 09:03:38.167859749 -0800 +++ b/fs/netfs/buffered_write.c 2025-01-29 09:03:38.171860082 -0800 @@ -152,16 +152,9 @@ ssize_t netfs_perform_write(struct kiocb offset = pos & (max_chunk - 1); part = min(max_chunk - offset, iov_iter_count(iter)); - /* Bring in the user pages that we will copy from _first_ lest - * we hit a nasty deadlock on copying from the same page as - * we're writing to, without it being marked uptodate. - * - * Not only is this an optimisation, but it is also required to - * check that the address is actually valid, when atomic - * usercopies are used below. - * - * We rely on the page being held onto long enough by the LRU - * that we can grab it below if this causes it to be read. + /* Bring in the user folios that are copied from before taking + * locks on the mapping folios. This helps ensure forward + * progress if they are the same folios. */ ret = -EFAULT; if (unlikely(fault_in_iov_iter_readable(iter, part) == part))