From patchwork Wed Apr 17 17:09:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13633674 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 504EA17277B; Wed, 17 Apr 2024 17:09:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713373791; cv=none; b=SXgBHcrRQFGw/OpKDZBqkt4T3n88j5GGGVE9E7C1XcAd/YosCKHve37TEbMF7MWrPs8ENOKedQiqNCzHK056AsKdnFyX2M0E5uHE/zZk3mnVKsjPoEwfMDxfIHitVUWj9FVp4mmDnJ+16vYRi+LrVeMEIvFTyAELq480A5IKil8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713373791; c=relaxed/simple; bh=cmaiNkl/cK+cmJoIQq3i7y1M7pu/CeYgGhABAaIDvMU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kSO7qOEfRvk1jHR9GFOakUY3Z2rG0Utfvir5mnR+asNpbjK6NaI7XnAgfKuLTsx6uOjY0O7PK43Ll5/4K27LzuZWmpIFktpT6gQxmwV9Tps6bGBjPyyff98ssa/bmHIlbiO59sSYHC9STS+eAPkJNeA9YLHxxSM8SRGP7I2SFr4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=NtiNMMvX; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="NtiNMMvX" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=9dr4ClrBHPYafianVPFPF3onj3SGS8CyeDvCS79fFaE=; b=NtiNMMvXVOLWt03g7n5zXetJwk GptA+3JKqAJjibaxXvj3tl5Umfy/bxCrbqfaAS/DBEaIjZO7nkjueQ7TxGBMbhIWvvwo3aissBR73 Vm3T8eyCpL8JjfwmS31Q0hmZg0tHKYU2mkgr5gQ0owJu7cmG0XCrA+h+WL7c7T3kTJVhtcmoyOl+J Fa9vn1FZBzXbd/0C/249SBnRqkr4BkHLg46m/hMA/GhHK6PNv4cmC/RbtU0hoywmcZH6o/S2ywmXS QEg+LYbpOh/JY9cvzIF+Jd2/qOF6mY4hKpU3vQF5wWoa3RPQ8aO44GQRgl4xmsRBo673H6aCyWR86 zI7+nBdA==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rx8n5-00000003LN4-2o1e; Wed, 17 Apr 2024 17:09:47 +0000 From: "Matthew Wilcox (Oracle)" To: Konstantin Komarov Cc: "Matthew Wilcox (Oracle)" , ntfs3@lists.linux.dev, linux-fsdevel@vger.kernel.org Subject: [PATCH 01/10] ntfs3: Convert ntfs_read_folio to use a folio Date: Wed, 17 Apr 2024 18:09:29 +0100 Message-ID: <20240417170941.797116-2-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240417170941.797116-1-willy@infradead.org> References: <20240417170941.797116-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove the struct page conversion, and use a folio throughout. We still convert back to a struct page for calling some internal functions, but those will change soon. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ntfs3/inode.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index 3c4c878f6d77..f833d9cd383d 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -698,25 +698,24 @@ static sector_t ntfs_bmap(struct address_space *mapping, sector_t block) static int ntfs_read_folio(struct file *file, struct folio *folio) { - struct page *page = &folio->page; int err; - struct address_space *mapping = page->mapping; + struct address_space *mapping = folio->mapping; struct inode *inode = mapping->host; struct ntfs_inode *ni = ntfs_i(inode); if (is_resident(ni)) { ni_lock(ni); - err = attr_data_read_resident(ni, page); + err = attr_data_read_resident(ni, &folio->page); ni_unlock(ni); if (err != E_NTFS_NONRESIDENT) { - unlock_page(page); + folio_unlock(folio); return err; } } if (is_compressed(ni)) { ni_lock(ni); - err = ni_readpage_cmpr(ni, page); + err = ni_readpage_cmpr(ni, &folio->page); ni_unlock(ni); return err; } From patchwork Wed Apr 17 17:09:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13633675 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 D130817166B; Wed, 17 Apr 2024 17:09:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713373792; cv=none; b=fJwmKkM/X+u4N0RvuM7Dv8rmsGRzf6eemSaqO89SYzlk1N5GMRYYjwMIAfZXxz1dglYgXpsc74uQ8aZHpd/A5DXp4LtW22p/DC2niaOWPzKpByHe/zajE2xevuD7ZmJUwfwqi5WzNux4kwy4NFzeWU6zagIPiWynYcrQA0ylSk0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713373792; c=relaxed/simple; bh=ZIQADL2PgbPutONs6shBGTMMzJYF/vEFFU9wUYLdnWM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eQdgMFLNETSBiTWBnLnrgNuj2Uv0R+4IHHITVOqke/2BvXUt8VSigFEk1A3Om6f0OnBr5Z88LghjEmaeBWjbMPKmGoio3qNLHIeZb/Tbw9N+WBJZ7JIarcrmcT/iifWG53C9G7un5FKpJVy/s5SLuzPpmu+7v1EABsyA28dkNT0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=N/Lsbot1; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="N/Lsbot1" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=8ReugmAKeubw491/vs0c3edm6WFEtt1rFDHXHFd0JCU=; b=N/Lsbot1AVRSr2pOvU7pi2xM3i VvNGgZf/iBp0dbCcnTeYgkaIUraSPq86EOwPy6UiLKbceaEE/hel2No4jOjDK2XSQlotJAu5KIpdR lmYkGFGHE9OmyQAbmXAn7uLiM96jG3DAInF6vM5Os16FfEH8WHK/2O567HfsusZz08yOXuL34xpuE D8uhI+fFZGUkkIbpmnDZX7z2OXHVZLZAFCni+SmhdeXfS79JdZzNx4emoH96PxF2xujr7Ic8r4Zp2 H8yo0r6WjC1mOorOUTLdnmLJL5nSW5ZTyg6HMGukPQXRhNv/kESi34pycM69W76eqnkbfHjwrZxfz U8pUAPew==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rx8n6-00000003LNA-1o09; Wed, 17 Apr 2024 17:09:48 +0000 From: "Matthew Wilcox (Oracle)" To: Konstantin Komarov Cc: "Matthew Wilcox (Oracle)" , ntfs3@lists.linux.dev, linux-fsdevel@vger.kernel.org Subject: [PATCH 02/10] ntfs3: Convert ntfs_write_begin to use a folio Date: Wed, 17 Apr 2024 18:09:30 +0100 Message-ID: <20240417170941.797116-3-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240417170941.797116-1-willy@infradead.org> References: <20240417170941.797116-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Retrieve a folio from the page cache instead of a precise page. This function is now large folio safe, but its called function is not. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ntfs3/inode.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index f833d9cd383d..25be12e68d6e 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -901,24 +901,25 @@ int ntfs_write_begin(struct file *file, struct address_space *mapping, *pagep = NULL; if (is_resident(ni)) { - struct page *page = - grab_cache_page_write_begin(mapping, pos >> PAGE_SHIFT); + struct folio *folio = __filemap_get_folio(mapping, + pos >> PAGE_SHIFT, FGP_WRITEBEGIN, + mapping_gfp_mask(mapping)); - if (!page) { - err = -ENOMEM; + if (IS_ERR(folio)) { + err = PTR_ERR(folio); goto out; } ni_lock(ni); - err = attr_data_read_resident(ni, page); + err = attr_data_read_resident(ni, &folio->page); ni_unlock(ni); if (!err) { - *pagep = page; + *pagep = &folio->page; goto out; } - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); if (err != E_NTFS_NONRESIDENT) goto out; From patchwork Wed Apr 17 17:09:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13633676 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 F369E172789; Wed, 17 Apr 2024 17:09:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713373793; cv=none; b=OVglVlvpBnggQvdenr/T8bzV/jD7yznuyrqCdQZvLqKRxCVnYauewn0ZLI5QTWV/umFMKOVID07RyLAgncuuf/UNlZ4wJ1RVA99DTGqIGQY2GS5JX1Tvq025pXlkl22x6f2ClylmvaB7dJ38UMJ/Fycda+PdWJVKWHqWG4rtsfE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713373793; c=relaxed/simple; bh=2O5Qj6YrSrtlVlal4UkAPlH0fYWyUVIhsdbsllxGHWY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CsG5UJ8Nsxp5mWlgGroVnrU2+9iHLkMIf/aclg4XbstLTvn3kZQ0Qjwx200IR17V+OOwN1W3SnKelCeLW0Q9L9Y0MxM2n4uyiOwofuPfkqV3Gzfrx7FgKFbvGhKSFAUXmdjlvxt2QMpoluymHiUXQX97xgeW5pDsdRtpKOprmQk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=ikj6U6iA; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ikj6U6iA" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=56DrERYxVwXpnm1O/3ISxLxUBwMsygo3JyURRzZ66aU=; b=ikj6U6iADp/cGQkuVI+v0Mce/L LJz3p2vv6ag33vCU03Fg/JSvR6rJYi93274Ya8nawaoP9+MVqDeH6wrPS9WgIXZELgh4KPi/FXhtH 6fHAS9mMz42wzneuYBdFfXW46CKV7zmjDDbv4l6NrH3Z4+W7IFAu0QXmtz1iF8Na9i76Jz8nL1q/J 8TUGt4RBHN3fcgouW96Y/hxgkIMA+Y/gzCjA9hSPkFE7NOnk2ZzIt3S0cybK+/8UhOBx2pLlobmtA 9X7caYn2O36oIj/Cs6vpwE/bO+uILh8h8sQCoUmeDFLw2soTGRJA+C4DFqIpfTmEOzk5V07pouNRd bra34HIQ==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rx8n7-00000003LNM-0aJu; Wed, 17 Apr 2024 17:09:49 +0000 From: "Matthew Wilcox (Oracle)" To: Konstantin Komarov Cc: "Matthew Wilcox (Oracle)" , ntfs3@lists.linux.dev, linux-fsdevel@vger.kernel.org Subject: [PATCH 03/10] ntfs3: Convert attr_data_read_resident() to take a folio Date: Wed, 17 Apr 2024 18:09:31 +0100 Message-ID: <20240417170941.797116-4-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240417170941.797116-1-willy@infradead.org> References: <20240417170941.797116-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that all three callers have a folio, pass it in and use folio_fill_tail() to do the hard work of filling the folio. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ntfs3/attrib.c | 27 +++++++++------------------ fs/ntfs3/inode.c | 6 +++--- fs/ntfs3/ntfs_fs.h | 2 +- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/fs/ntfs3/attrib.c b/fs/ntfs3/attrib.c index 7aadf5010999..11f90b140122 100644 --- a/fs/ntfs3/attrib.c +++ b/fs/ntfs3/attrib.c @@ -1223,11 +1223,12 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn, goto out; } -int attr_data_read_resident(struct ntfs_inode *ni, struct page *page) +int attr_data_read_resident(struct ntfs_inode *ni, struct folio *folio) { u64 vbo; struct ATTRIB *attr; u32 data_size; + size_t len; attr = ni_find_attr(ni, NULL, NULL, ATTR_DATA, NULL, 0, NULL, NULL); if (!attr) @@ -1236,25 +1237,15 @@ int attr_data_read_resident(struct ntfs_inode *ni, struct page *page) if (attr->non_res) return E_NTFS_NONRESIDENT; - vbo = page->index << PAGE_SHIFT; + vbo = folio->index << PAGE_SHIFT; data_size = le32_to_cpu(attr->res.data_size); - if (vbo < data_size) { - const char *data = resident_data(attr); - char *kaddr = kmap_atomic(page); - u32 use = data_size - vbo; - - if (use > PAGE_SIZE) - use = PAGE_SIZE; + if (vbo > data_size) + len = 0; + else + len = min(data_size - vbo, folio_size(folio)); - memcpy(kaddr, data + vbo, use); - memset(kaddr + use, 0, PAGE_SIZE - use); - kunmap_atomic(kaddr); - flush_dcache_page(page); - SetPageUptodate(page); - } else if (!PageUptodate(page)) { - zero_user_segment(page, 0, PAGE_SIZE); - SetPageUptodate(page); - } + folio_fill_tail(folio, 0, resident_data(attr) + vbo, len); + folio_mark_uptodate(folio); return 0; } diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index 25be12e68d6e..1eb11c3b480d 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -571,7 +571,7 @@ static noinline int ntfs_get_block_vbo(struct inode *inode, u64 vbo, if (is_resident(ni)) { ni_lock(ni); - err = attr_data_read_resident(ni, &folio->page); + err = attr_data_read_resident(ni, folio); ni_unlock(ni); if (!err) @@ -705,7 +705,7 @@ static int ntfs_read_folio(struct file *file, struct folio *folio) if (is_resident(ni)) { ni_lock(ni); - err = attr_data_read_resident(ni, &folio->page); + err = attr_data_read_resident(ni, folio); ni_unlock(ni); if (err != E_NTFS_NONRESIDENT) { folio_unlock(folio); @@ -911,7 +911,7 @@ int ntfs_write_begin(struct file *file, struct address_space *mapping, } ni_lock(ni); - err = attr_data_read_resident(ni, &folio->page); + err = attr_data_read_resident(ni, folio); ni_unlock(ni); if (!err) { diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index ea5b5e814e63..0b518bf8182a 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -434,7 +434,7 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type, struct ATTRIB **ret); int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn, CLST *len, bool *new, bool zero); -int attr_data_read_resident(struct ntfs_inode *ni, struct page *page); +int attr_data_read_resident(struct ntfs_inode *ni, struct folio *folio); int attr_data_write_resident(struct ntfs_inode *ni, struct page *page); int attr_load_runs_vcn(struct ntfs_inode *ni, enum ATTR_TYPE type, const __le16 *name, u8 name_len, struct runs_tree *run, From patchwork Wed Apr 17 17:09:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13633677 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 9AFE2172796; Wed, 17 Apr 2024 17:09:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713373794; cv=none; b=ZJ2wU/XJnKNpHlgFI5NY9uP7Qw5Dy+QFDcGPpU4tkoh2i1uzsE7GZxD3XscI5a11ZLX39/zmdv7b67w3xBdz6Qp1lybJFWGiP2KPqbuFWEDL3krGMgAobMKeaz015n9nVblGiYcjsdiGHfyxFzrH4EiEcaLg5J37P5VvRtoeq8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713373794; c=relaxed/simple; bh=UiymJav+ACgwnnTqZhZOJCG1ZgXeoBStmosnsPpXk84=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V/RY040rGiNGCk7/eNdsEoWxj/3pkvxh24Bt+MoXVqgE6zj0lvGl9OCMpUXE0MNZcV3SDehmnDAAAG27p1x8UGvf7j04qoGbIHRecj8gFlOJEogL9xpP4kjqnqbM8OjSBMwm3WeHJk308pY9JPrQIxXG7qhnb4R2IQpjPeYDqxA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=J2T2crc1; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="J2T2crc1" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=7bZeS0mEdRY/gU0MkUgofDOebQU6IakHlHbte6xXEK4=; b=J2T2crc1kwpQ+zbrZpppXPQjVT JsRtGj9yHVyQgenHPtlw8Q9LH24kBPgayR3XGOKFfjiC0BxAJnKcWaq0bmFJMZvflgoSngtFpiPib E7MBuIL4CiOugxk0kFvmgjP5cBP7Xgc+fI/+3wUNpbgACni05SS+cWzIFUGCPrmJ6JhTaIIo9DDUt pIX6Y7y57awYZm5sKQU/fZ891XuMZ2eBS4cy5wDcrycyjCP33laZB9aN4GguwVGeWIcBzoP4z6DBD wNtAi20IhNVBudhLgjqZ8eEqJ6NUTYMaRSdU7kYTySwxcErLZxLIlM3/dX7S/zmda8UuJ1MHq/K+q lfSmlkEA==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rx8n7-00000003LNS-3pry; Wed, 17 Apr 2024 17:09:50 +0000 From: "Matthew Wilcox (Oracle)" To: Konstantin Komarov Cc: "Matthew Wilcox (Oracle)" , ntfs3@lists.linux.dev, linux-fsdevel@vger.kernel.org Subject: [PATCH 04/10] ntfs3: Convert ntfs_write_end() to work on a folio Date: Wed, 17 Apr 2024 18:09:32 +0100 Message-ID: <20240417170941.797116-5-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240417170941.797116-1-willy@infradead.org> References: <20240417170941.797116-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Convert the passed page back into a folio and use the folio APIs, saving a few hidden calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) --- fs/ntfs3/inode.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index 1eb11c3b480d..e649d191554d 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -938,6 +938,7 @@ int ntfs_write_begin(struct file *file, struct address_space *mapping, int ntfs_write_end(struct file *file, struct address_space *mapping, loff_t pos, u32 len, u32 copied, struct page *page, void *fsdata) { + struct folio *folio = page_folio(page); struct inode *inode = mapping->host; struct ntfs_inode *ni = ntfs_i(inode); u64 valid = ni->i_valid; @@ -949,23 +950,23 @@ int ntfs_write_end(struct file *file, struct address_space *mapping, loff_t pos, err = attr_data_write_resident(ni, page); ni_unlock(ni); if (!err) { + struct buffer_head *head = folio_buffers(folio); dirty = true; - /* Clear any buffers in page. */ - if (page_has_buffers(page)) { - struct buffer_head *head, *bh; + /* Clear any buffers in folio. */ + if (head) { + struct buffer_head *bh = head; - bh = head = page_buffers(page); do { clear_buffer_dirty(bh); clear_buffer_mapped(bh); set_buffer_uptodate(bh); } while (head != (bh = bh->b_this_page)); } - SetPageUptodate(page); + folio_mark_uptodate(folio); err = copied; } - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); } else { err = generic_write_end(file, mapping, pos, len, copied, page, fsdata); From patchwork Wed Apr 17 17:09:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13633678 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 2AA8017166B; Wed, 17 Apr 2024 17:09:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713373794; cv=none; b=Zej0y5YhpwQbjClE201eGrrZv5FonHJLyBnUmYLG42lTsyEpFWnPL6yqwnNtP4LzGsPSTfcN5OAiHbVam6o35aQo2VASgdD0oRBcbPLFrGMklTgu2GUZO4sNIaMJYplhHAVYbO9iGMzYnmYZD4B+6pyuYqNo4hBsMvwAgFxYgCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713373794; c=relaxed/simple; bh=EAQDFPEy6cQ4YkGhr+2EUXffLxBkkeq8LcO6iBwOLKQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E0PZmIs507c3KELOg+We9xzNmSqy+PoZxsRbbAjvuAWch5I0gNVYY8ppHa918Q4yU2IgP+NexPVOQagtGBmoTz9bbXZhRl2lvRnF9p93c5hpd4/8TVMr1V25d+RXGW1jEbJQ5p+b6DsWc4YFBaoldi0pvQHuHd0ihjcDXA68JyA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=lSK55F7H; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="lSK55F7H" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=S3wehsEJVgq9ww+YHdEdObRQcvwJ3zi7CoaRl0ZoYQk=; b=lSK55F7HfZvfr8Y9BIiVX423ZJ nMJArF65Swg+93Y40jQ48IE51W8rc30NOpHgzoMOvytmjaxOrOT9mI6QKQqZL3Z3tKq2/qWAcsVxF wsgR1I9vOjKO2u0chzfRDmfzTtHo0HohAXyB/sV8IUHZVHi0cFj+rVASuQcaRFaU4IyV7YFzukCPb WxKzzxSDi37hBW/JNWhEX6mCmxQX9LoiGqnhQ2BiGN6CFCPlVpwluUWznCXyDx6eFpfgVfmZen5rq FdqZ5cBkIT4BP8W3jr43iduvFpjucOp7o8jgr1XtUFyEuTZhmJVsRhjNswjiFWVR2tLwicTWDkTmI FOkfl1iw==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rx8n8-00000003LNY-2yUv; Wed, 17 Apr 2024 17:09:50 +0000 From: "Matthew Wilcox (Oracle)" To: Konstantin Komarov Cc: "Matthew Wilcox (Oracle)" , ntfs3@lists.linux.dev, linux-fsdevel@vger.kernel.org Subject: [PATCH 05/10] ntfs3: Convert attr_data_write_resident to use a folio Date: Wed, 17 Apr 2024 18:09:33 +0100 Message-ID: <20240417170941.797116-6-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240417170941.797116-1-willy@infradead.org> References: <20240417170941.797116-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that both callers of attr_data_write_resident() have a folio, pass it in and use memcpy_from_folio() to handle all the gnarly highmem multi-page problems. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ntfs3/attrib.c | 12 ++++-------- fs/ntfs3/inode.c | 4 ++-- fs/ntfs3/ntfs_fs.h | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/fs/ntfs3/attrib.c b/fs/ntfs3/attrib.c index 11f90b140122..64b526fd2dbc 100644 --- a/fs/ntfs3/attrib.c +++ b/fs/ntfs3/attrib.c @@ -1250,7 +1250,7 @@ int attr_data_read_resident(struct ntfs_inode *ni, struct folio *folio) return 0; } -int attr_data_write_resident(struct ntfs_inode *ni, struct page *page) +int attr_data_write_resident(struct ntfs_inode *ni, struct folio *folio) { u64 vbo; struct mft_inode *mi; @@ -1266,17 +1266,13 @@ int attr_data_write_resident(struct ntfs_inode *ni, struct page *page) return E_NTFS_NONRESIDENT; } - vbo = page->index << PAGE_SHIFT; + vbo = folio->index << PAGE_SHIFT; data_size = le32_to_cpu(attr->res.data_size); if (vbo < data_size) { char *data = resident_data(attr); - char *kaddr = kmap_atomic(page); - u32 use = data_size - vbo; + size_t len = min(data_size - vbo, folio_size(folio)); - if (use > PAGE_SIZE) - use = PAGE_SIZE; - memcpy(data + vbo, kaddr, use); - kunmap_atomic(kaddr); + memcpy_from_folio(data + vbo, folio, 0, len); mi->dirty = true; } ni->i_valid = data_size; diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index e649d191554d..cd634398d770 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -859,7 +859,7 @@ static int ntfs_resident_writepage(struct folio *folio, return -EIO; ni_lock(ni); - ret = attr_data_write_resident(ni, &folio->page); + ret = attr_data_write_resident(ni, folio); ni_unlock(ni); if (ret != E_NTFS_NONRESIDENT) @@ -947,7 +947,7 @@ int ntfs_write_end(struct file *file, struct address_space *mapping, loff_t pos, if (is_resident(ni)) { ni_lock(ni); - err = attr_data_write_resident(ni, page); + err = attr_data_write_resident(ni, folio); ni_unlock(ni); if (!err) { struct buffer_head *head = folio_buffers(folio); diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index 0b518bf8182a..d35dc001c2c0 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -435,7 +435,7 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type, int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn, CLST *len, bool *new, bool zero); int attr_data_read_resident(struct ntfs_inode *ni, struct folio *folio); -int attr_data_write_resident(struct ntfs_inode *ni, struct page *page); +int attr_data_write_resident(struct ntfs_inode *ni, struct folio *folio); int attr_load_runs_vcn(struct ntfs_inode *ni, enum ATTR_TYPE type, const __le16 *name, u8 name_len, struct runs_tree *run, CLST vcn); From patchwork Wed Apr 17 17:09:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13633679 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 D726417279D; Wed, 17 Apr 2024 17:09:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713373795; cv=none; b=CkaY795JOmZ0Qz3cxG3sxFkDAe4m8WFrvVbk8zGiKYp424/HW2sqXikK5koXONM4OVpoCv2J1VuBlomrbF/+jiSHe1AmNQVZezR0g8/Xw8pPE65ZrThi/4Vug4imnh8vKOjh3iue+QKj5wh6i0X54+KihCtqQ7gMZ2syZNaNwDs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713373795; c=relaxed/simple; bh=CDnMjQ0eIq/BOOB5K1hTv1DH3NrskCdniKfZmQlYmrE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kdiYl61vPOdoaGe+BLYBqZ1Xv3LCPYbJ5oeinHpa4WO47vPvFC3/dbSWUJMJcvcJp/zZdZhdlhkHpH5+MBoPVFYQNPp6XqMJa23HgqQtmxm6c3AukZOmUV6pNoPToC+MR2nyGhO7eOG3fV4svKGMcGQ8CqX7S2XDsHyPuQrHRc0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=YivVIEb7; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="YivVIEb7" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=IjoxSp91HE+rrlkrHRhOXkk1Xtc4SU3NQ66FrwDSlT8=; b=YivVIEb77nAuMVs0588t8biM4m agxqI/Y+JUqlmRci4OggVPS6gON2+dllcOQW1+ewlr8zavTpfYoBgLu+pA8oQAyr5Vki6wy3IzT0o wVRhFhvFAEz9TzCcQZ37ffGpKPR1cupyV4YgWPndiX+a958lugKZ0rTikc+Q366dvXFcExppJl+7H qsdnwX9GNKvKVNxpCNVXgldKkgQO//bptvxJiv0SNwvsWQZV0cRsR3Sy3JnGh2KVhywzW2obrzTr5 KJT//l21Kv1e3nAOZAuwq/3sbTlTK448SNHUFD5dQG41x8PP9N02YFEz+5BhYnPZo5FgDEAVmyA0T z/QWou4w==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rx8n9-00000003LNe-0oFB; Wed, 17 Apr 2024 17:09:51 +0000 From: "Matthew Wilcox (Oracle)" To: Konstantin Komarov Cc: "Matthew Wilcox (Oracle)" , ntfs3@lists.linux.dev, linux-fsdevel@vger.kernel.org Subject: [PATCH 06/10] ntfs3: Convert attr_make_nonresident to use a folio Date: Wed, 17 Apr 2024 18:09:34 +0100 Message-ID: <20240417170941.797116-7-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240417170941.797116-1-willy@infradead.org> References: <20240417170941.797116-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Fetch a folio from the page cache instead of a page and operate on it. Take advantage of the new helpers to avoid handling highmem ourselves, and combine the uptodate + unlock operations into folio_end_read(). Signed-off-by: Matthew Wilcox (Oracle) --- fs/ntfs3/attrib.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/fs/ntfs3/attrib.c b/fs/ntfs3/attrib.c index 64b526fd2dbc..1972213a663e 100644 --- a/fs/ntfs3/attrib.c +++ b/fs/ntfs3/attrib.c @@ -285,22 +285,20 @@ int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr, if (err) goto out2; } else if (!page) { - char *kaddr; - - page = grab_cache_page(ni->vfs_inode.i_mapping, 0); - if (!page) { - err = -ENOMEM; + struct address_space *mapping = ni->vfs_inode.i_mapping; + struct folio *folio; + + folio = __filemap_get_folio(mapping, 0, + FGP_LOCK | FGP_ACCESSED | FGP_CREAT, + mapping_gfp_mask(mapping)); + if (IS_ERR(folio)) { + err = PTR_ERR(folio); goto out2; } - kaddr = kmap_atomic(page); - memcpy(kaddr, data, rsize); - memset(kaddr + rsize, 0, PAGE_SIZE - rsize); - kunmap_atomic(kaddr); - flush_dcache_page(page); - SetPageUptodate(page); - set_page_dirty(page); - unlock_page(page); - put_page(page); + folio_fill_tail(folio, 0, data, rsize); + folio_mark_dirty(folio); + folio_end_read(folio, true); + folio_put(folio); } } From patchwork Wed Apr 17 17:09:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13633680 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 0690A171640; Wed, 17 Apr 2024 17:09:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713373795; cv=none; b=RPxwyakcU54S7ytVgKuzPbTtx5ParJlqCLYRn56n9XvxTSVJJWO3SnfJMuzYNHw1K5YDuCJz41CPPCgbpy5ba/b4W20kQiYObzIMnvFM7nJ0qLTjxnb0/kAcDdppYS1UHU1JTIJClkKyF9JW0sKynAhyPZh3ZbLQnjxQOSOTrag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713373795; c=relaxed/simple; bh=DpVHRUtZmw09qOBriykBMM3ziyBXu+Njf0EOYqDFKXE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z87F5SauSh8a9+krhThtOVOAAtaL5W7xbWJHQp7D73BEITZVhG/a5WSpLO6jQ9KM+w8W8yK/4KDw/ksc5ZTyvs6rV9lnQ1POpyTqi3tb9+ZklwLr0YxuyC1u6EUjsY/BRe16ZYffXGGpcs8FVtWA6l+rbPEHltP1HXDSc4uCiio= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=BQKRFwAs; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="BQKRFwAs" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=Gd/hLk3fvNrVja4FG3MXbWsqnGurE8K7zthCOdTqPwA=; b=BQKRFwAsS6FTLEi9Vc5iQ1iWMJ yFWGVq4ySEVBQ+r9kTf3bWPuquRcUq+ny74eAcvLOFgBuObmexrGyjK5H3n5PYNYFqMSbuePin2bU 29c8fE54tdC7bHTvmSG/AcmhlDH81w8McWcKK0eqzxc4GlVdLlv2qDe1OeKOXjt070SVb9vQkeSsb r7eoxkWBjN/Y2VkxGBAObuPcGW1ahWhF4nJrDUG2q+4q0CpuyJESEUuR/OEzy2kU5uahBN1/enkWm V8ol8TU0W94CveDok3MCm/pPugymO9fA+BbZlrXSKt2gqKihum3B5nnrqc5HO9HbB+mKXz5PGI+7I QllVxQdA==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rx8n9-00000003LNk-2Z3h; Wed, 17 Apr 2024 17:09:52 +0000 From: "Matthew Wilcox (Oracle)" To: Konstantin Komarov Cc: "Matthew Wilcox (Oracle)" , ntfs3@lists.linux.dev, linux-fsdevel@vger.kernel.org Subject: [PATCH 07/10] ntfs3: Convert reading $AttrDef to use folios Date: Wed, 17 Apr 2024 18:09:35 +0100 Message-ID: <20240417170941.797116-8-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240417170941.797116-1-willy@infradead.org> References: <20240417170941.797116-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This is now large folio safe, although we're not enabling large folios yet. It does eliminate a use of kmap(). Signed-off-by: Matthew Wilcox (Oracle) --- fs/ntfs3/super.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index 71dfeb0c4323..f6a9ab0f5cad 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -1429,18 +1429,22 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc) goto put_inode_out; } - for (done = idx = 0; done < bytes; done += PAGE_SIZE, idx++) { + done = idx = 0; + while (done < bytes) { unsigned long tail = bytes - done; - struct page *page = ntfs_map_page(inode->i_mapping, idx); + struct folio *folio = read_mapping_folio(inode->i_mapping, + idx, NULL); - if (IS_ERR(page)) { - err = PTR_ERR(page); + if (IS_ERR(folio)) { + err = PTR_ERR(folio); ntfs_err(sb, "Failed to read $AttrDef (%d).", err); goto put_inode_out; } - memcpy(Add2Ptr(t, done), page_address(page), - min(PAGE_SIZE, tail)); - ntfs_unmap_page(page); + memcpy_from_folio(Add2Ptr(t, done), folio, 0, + min(tail, folio_size(folio))); + done += folio_size(folio); + idx += folio_nr_pages(folio); + folio_put(folio); if (!idx && ATTR_STD != t->type) { ntfs_err(sb, "$AttrDef is corrupted."); From patchwork Wed Apr 17 17:09:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13633681 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 789DB172BA8; Wed, 17 Apr 2024 17:09:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713373795; cv=none; b=qk+mIBYWrTj0Hw4DkdMpCR8wjpoPNj24RB/MBsXd91OBwjMPVUNYGw14vedfo0fMf42iOBvqRwfcZ5cSFN8KYTdLdvcX/RuXVtQ5P2C76gklVx+sGwXkk26cUuqsxlkwaJB6FM8AMOw8pGvpVvHl7ND+88jgY+t9Dj23dUIw16Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713373795; c=relaxed/simple; bh=IsgfukMEwJW9jhqCmijzm0Xn8L9yo1SpFpxIm0dhqIw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nitdmjx7mvUAWJtAGYQbAE9vzwhhIBjqGGSN6gMZyqh2IvbNEmUFqx3XwvLvSS3dwv+H6e5fdGkls2/4YIRYziKHukVcvOuHftvbDKvZP0NSzX0BTSAcoxN6Pd9M+E+Aaizg5xM17DBbE1ROPIM8wX3azkYFyzwESmXW+e1lj/Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=wGxSJXSO; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="wGxSJXSO" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=sVLC2SOQAmPn3AChIpktUkfkcZacBQhX9T6iZ3X49dw=; b=wGxSJXSOGxb7ow+NiJGvKONh3s 0n4bEC3355TGPgFtN5HQX0ri6WwWKTI5xek/APzDRZZPQnuhTzZGx64Zr++JKB2f6M7PSkZRb8/9T JQih9FMPY2cAhtNvjMRebOiXudwawExikjuNQPdKj+7qmftk/pzCv6uVcFTc1Bnm3fo5f4808ByES F8O/G7mmAu7nkkbQfJ/SFNv37RqIuJSyxl7FCZ7CKTE0ucs21vvr2OVTDziwpKCeaTkHYp0a6WF1A ONBHHZdTF3qJxrz6Wzg2zQPnjTHNPky7Ww9ZIKra9Xybaji5V50hgCrhv2+lsqq9r7zXPPPXvHVhi tNmSSL1A==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rx8nA-00000003LNq-15py; Wed, 17 Apr 2024 17:09:52 +0000 From: "Matthew Wilcox (Oracle)" To: Konstantin Komarov Cc: "Matthew Wilcox (Oracle)" , ntfs3@lists.linux.dev, linux-fsdevel@vger.kernel.org Subject: [PATCH 08/10] ntfs3: Use a folio to read UpCase Date: Wed, 17 Apr 2024 18:09:36 +0100 Message-ID: <20240417170941.797116-9-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240417170941.797116-1-willy@infradead.org> References: <20240417170941.797116-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a memcpy_from_folio_le16() which does the byteswapping. This is now large folio safe and avoids kmap(). Signed-off-by: Matthew Wilcox (Oracle) --- fs/ntfs3/super.c | 25 +++++++++++-------------- include/linux/highmem.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index f6a9ab0f5cad..00700598a717 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -1493,26 +1493,23 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc) goto put_inode_out; } - for (idx = 0; idx < (0x10000 * sizeof(short) >> PAGE_SHIFT); idx++) { - const __le16 *src; + idx = 0; + while (idx < (0x10000 * sizeof(u16) >> PAGE_SHIFT)) { u16 *dst = Add2Ptr(sbi->upcase, idx << PAGE_SHIFT); - struct page *page = ntfs_map_page(inode->i_mapping, idx); + struct folio *folio = read_mapping_folio(inode->i_mapping, + idx, NULL); + size_t limit = 0x10000 * sizeof(u16) - idx * PAGE_SIZE; - if (IS_ERR(page)) { - err = PTR_ERR(page); + if (IS_ERR(folio)) { + err = PTR_ERR(folio); ntfs_err(sb, "Failed to read $UpCase (%d).", err); goto put_inode_out; } - src = page_address(page); - -#ifdef __BIG_ENDIAN - for (i = 0; i < PAGE_SIZE / sizeof(u16); i++) - *dst++ = le16_to_cpu(*src++); -#else - memcpy(dst, src, PAGE_SIZE); -#endif - ntfs_unmap_page(page); + memcpy_from_folio_le16(dst, folio, 0, + min(limit, folio_size(folio))); + idx += folio_nr_pages(folio); + folio_put(folio); } shared = ntfs_set_shared(sbi->upcase, 0x10000 * sizeof(short)); diff --git a/include/linux/highmem.h b/include/linux/highmem.h index 00341b56d291..20b5d5a5feaf 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -467,6 +467,37 @@ static inline void memcpy_from_folio(char *to, struct folio *folio, } while (len > 0); } +#ifdef __BIG_ENDIAN +static inline void memcpy_from_folio_le16(u16 *to, struct folio *folio, + size_t offset, size_t len) +{ + VM_BUG_ON(offset + len > folio_size(folio)); + + do { + const __le16 *from = kmap_local_folio(folio, offset); + size_t chunk = len; + + if (folio_test_highmem(folio) && + chunk > PAGE_SIZE - offset_in_page(offset)) + chunk = PAGE_SIZE - offset_in_page(offset); + + for (i = 0; i < chunk / sizeof(*to); i++) + *to++ = le16_to_cpu(*from++); + kunmap_local(from); + + to += chunk / sizeof(*to); + offset += chunk; + len -= chunk; + } while (len > 0); +} +#else +static inline void memcpy_from_folio_le16(u16 *to, struct folio *folio, + size_t offset, size_t len) +{ + memcpy_from_folio((char *)to, folio, offset, len); +} +#endif + /** * memcpy_to_folio - Copy a range of bytes to a folio. * @folio: The folio to write to. From patchwork Wed Apr 17 17:09:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13633683 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 511DC172BC3; Wed, 17 Apr 2024 17:09:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713373797; cv=none; b=BVjE8rYr5kHuupZt3KRxbcKskIq9qkAQvSStHSst3oV+aOZmnP6FHIzP8vwHxnPPw62USQYQtHbjhSN0Hcebfq4SCE47g2kVL0nYdqdR1v4ml2wAabs7OwrdPlRxjtr0NfJlcXF4Du4IrssCbYY7BE0m8Z/b/mZ5+Q/5bxWB7dc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713373797; c=relaxed/simple; bh=dENt5TGLtcqwH8n2n6+/ROVruoKRRQ0LEMgNut1PvKA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OtoodMaoHOhd7BICdt+MIzbOFRd22Knv7sVV1OcRgqDnv2rOVHkD00cnWjMqMbyE9Vey2+2DilQnQvuUFDmWK/rlIFpONR7bw5HiRPGrFYRc/3y1EbbA5gfWiZqliWhknyf+ChtErG+2VQAzdwRun+lxqoIR/haAMBni3dnVKJE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=wVteX4Ez; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="wVteX4Ez" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=BcwRdNxr+GiV+q3NXyqNKiazMO4WpYoF8YYTvyFIEjM=; b=wVteX4Ez2wlaKoEBLTUG5gCboI ngICImHPkm9hNFVv2MCEI0/MvZk5+sJNJWpK/DZmDMtK2XWJJ+c5KQ/xBXjXCcZsD5COHujZIWsd/ I0yMKD0mTPZKraai32/4yhMByJIcqvbjFjlQvpWA4wIXyEPzblUjUdx/HuE4ohiD+hMIn48TGogml bukd5NH4cE8z/icZkv71cLiAAuYvmEFvFUoB41o+01SOsBHv7WzzpbdJ+M7nQ95I6qoQ7qCDS3BmL cVDXH4G0wFX/kD16jnXu5dC9q5mFTivjBSs3W1YseECQy9MQ9Sn7Uz+Spm2tfP0l5TjMR5NQFjGmL vygCtB7w==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rx8nA-00000003LNx-3ad3; Wed, 17 Apr 2024 17:09:53 +0000 From: "Matthew Wilcox (Oracle)" To: Konstantin Komarov Cc: "Matthew Wilcox (Oracle)" , ntfs3@lists.linux.dev, linux-fsdevel@vger.kernel.org Subject: [PATCH 09/10] ntfs3: Remove inode_write_data() Date: Wed, 17 Apr 2024 18:09:37 +0100 Message-ID: <20240417170941.797116-10-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240417170941.797116-1-willy@infradead.org> References: <20240417170941.797116-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This function has no callers, so remove it. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ntfs3/inode.c | 30 ------------------------------ fs/ntfs3/ntfs_fs.h | 1 - 2 files changed, 31 deletions(-) diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index cd634398d770..693e8b2f562e 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -1086,36 +1086,6 @@ int ntfs_flush_inodes(struct super_block *sb, struct inode *i1, return ret; } -int inode_write_data(struct inode *inode, const void *data, size_t bytes) -{ - pgoff_t idx; - - /* Write non resident data. */ - for (idx = 0; bytes; idx++) { - size_t op = bytes > PAGE_SIZE ? PAGE_SIZE : bytes; - struct page *page = ntfs_map_page(inode->i_mapping, idx); - - if (IS_ERR(page)) - return PTR_ERR(page); - - lock_page(page); - WARN_ON(!PageUptodate(page)); - ClearPageUptodate(page); - - memcpy(page_address(page), data, op); - - flush_dcache_page(page); - SetPageUptodate(page); - unlock_page(page); - - ntfs_unmap_page(page); - - bytes -= op; - data = Add2Ptr(data, PAGE_SIZE); - } - return 0; -} - /* * ntfs_reparse_bytes * diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index d35dc001c2c0..1582cde21988 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -713,7 +713,6 @@ int ntfs3_write_inode(struct inode *inode, struct writeback_control *wbc); int ntfs_sync_inode(struct inode *inode); int ntfs_flush_inodes(struct super_block *sb, struct inode *i1, struct inode *i2); -int inode_write_data(struct inode *inode, const void *data, size_t bytes); struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir, struct dentry *dentry, const struct cpu_str *uni, umode_t mode, From patchwork Wed Apr 17 17:09:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13633682 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 533BD172BC4; Wed, 17 Apr 2024 17:09:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713373796; cv=none; b=SYMrZSRiJZ9FX3tbjmSJhRbCxBIlMgo3Ei2izPCod1cHKkXNjQWP8SGktU4+EN8bgLYlIAwK/RIXw+OBqf3nzjXxxCvija2UcbX0WDzjg/JkgE3o9uGmYHGUI5/FA8mY53CCpiXIc+EwTAczbAd0nPMQx9o3OU+xm9Xr5D9/1FU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713373796; c=relaxed/simple; bh=hhyT8NyjB+05U7DjUTa8gI8Gwbdxanhqbs9YNcx1xNQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fa92abCSWeLpNZcm7XG3zovtxZQOhM8zS9PfuWKORuPY3AZyhZZ8l/aIxCnNRES5BxSrMvbArlbpGo5xnPy/HDLV9NmXXSe5W4Y/CwB2XoeK031SJx0QLMyvFdjx6qLZ1/Dh87sAH/w97cjqoTpbeXWlE6CBN9recq6G06SbiuA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=ENoXTYFU; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ENoXTYFU" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=fpKWg49bgezfZO5bk51+dX+JEDPDXpjRn8QsOv7hfOw=; b=ENoXTYFU6E2FrjCDoEwrWsVUdp TFdDmTmCnLFGhA1IvQk2JeQy/z2VLu92JJ9JhfL16Vi91HBJLbZv4eGCexHYT9uWyB3663asRiZYA wg2HvWKpmqJZ73wA3lJwJVgkuoD+mivojtHkToKG+j/h1JFXBLAFTU8oU5c2PH557zaNnO65HP44O fapPIMU0WE+XUj8yksctQ3DKt1/+8wbZD2pG+PilOkMkzYWkZe84lymSgxU/hMpuJWeQOjxKiDrx1 c0e8fCgGEZRCO5bgBVHIf3FpLVxsgwFGw2v7PzwKDq61AEa3TXxDB2sjgysVKNEhFcw+MAAfZoWIS YnqBCoOw==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rx8nB-00000003LO3-29MZ; Wed, 17 Apr 2024 17:09:53 +0000 From: "Matthew Wilcox (Oracle)" To: Konstantin Komarov Cc: "Matthew Wilcox (Oracle)" , ntfs3@lists.linux.dev, linux-fsdevel@vger.kernel.org Subject: [PATCH 10/10] ntfs3: Remove ntfs_map_page and ntfs_unmap_page Date: Wed, 17 Apr 2024 18:09:38 +0100 Message-ID: <20240417170941.797116-11-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240417170941.797116-1-willy@infradead.org> References: <20240417170941.797116-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 These functions have no more callers, so remove them. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ntfs3/ntfs_fs.h | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index 1582cde21988..c3f71a47fd17 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -907,22 +907,6 @@ static inline bool ntfs_is_meta_file(struct ntfs_sb_info *sbi, CLST rno) rno == sbi->usn_jrnl_no; } -static inline void ntfs_unmap_page(struct page *page) -{ - kunmap(page); - put_page(page); -} - -static inline struct page *ntfs_map_page(struct address_space *mapping, - unsigned long index) -{ - struct page *page = read_mapping_page(mapping, index, NULL); - - if (!IS_ERR(page)) - kmap(page); - return page; -} - static inline size_t wnd_zone_bit(const struct wnd_bitmap *wnd) { return wnd->zone_bit;