Skip to contentSkip to conversation

fs/ntfs3: return folios from ntfs_lock_new_page()

PATCH Superseded Sun Jian 3 participants 6 messages Feb 5 – Feb 24 NTFS3 filesystem

lore
Share & tools
lore

Sun Jian

author
#0 lore raw

PATCH 1/1 fs/ntfs3: return folios from ntfs_lock_new_page()

ntfs_lock_new_page() currently returns a struct page * but it primarily operates on folios via __filemap_get_folio(). Convert it to return a struct folio * and use folio_alloc() + __folio_set_locked() for the temporary page used to avoid data corruption during decompression.

When the cached folio is not uptodate, keep the existing behavior by calling folio_file_page() and converting the returned page back to a folio. Defensively handle error pointers from folio_file_page().

ni_readpage_cmpr() is updated to consume the folio return value while keeping the existing page array and cleanup logic unchanged.

---
 fs/ntfs3/frecord.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)
fs/ntfs3/frecord.c +19 -14
index 641ddaf8d4a0..a23aaf34f001 100644
@@ -2022,27 +2022,31 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_extent_info *fieinfo,
 	return err;
 }
 
-static struct page *ntfs_lock_new_page(struct address_space *mapping,
-		pgoff_t index, gfp_t gfp)
+static struct folio *ntfs_lock_new_page(struct address_space *mapping,
+					pgoff_t index, gfp_t gfp)
 {
 	struct folio *folio = __filemap_get_folio(mapping, index,
 			FGP_LOCK | FGP_ACCESSED | FGP_CREAT, gfp);
-	struct page *page;
 
 	if (IS_ERR(folio))
-		return ERR_CAST(folio);
+		return folio;
 
-	if (!folio_test_uptodate(folio))
-		return folio_file_page(folio, index);
+	if (!folio_test_uptodate(folio)) {
+		struct page *page = folio_file_page(folio, index);
+
+		if (IS_ERR(page))
+			return ERR_CAST(page);
+		return page_folio(page);
+	}
 
 	/* Use a temporary page to avoid data corruption */
 	folio_unlock(folio);
 	folio_put(folio);
-	page = alloc_page(gfp);
-	if (!page)
+	folio = folio_alloc(gfp, 0);
+	if (!folio)
 		return ERR_PTR(-ENOMEM);
-	__SetPageLocked(page);
-	return page;
+	__folio_set_locked(folio);
+	return folio;
 }
 
 /*
@@ -2064,6 +2068,7 @@ int ni_readpage_cmpr(struct ntfs_inode *ni, struct folio *folio)
 	u32 i, idx, frame_size, pages_per_frame;
 	gfp_t gfp_mask;
 	struct page *pg;
+	struct folio *f;
 
 	if (vbo >= i_size_read(&ni->vfs_inode)) {
 		folio_zero_range(folio, 0, folio_size(folio));
@@ -2099,12 +2104,12 @@ int ni_readpage_cmpr(struct ntfs_inode *ni, struct folio *folio)
 		if (i == idx)
 			continue;
 
-		pg = ntfs_lock_new_page(mapping, index, gfp_mask);
-		if (IS_ERR(pg)) {
-			err = PTR_ERR(pg);
+		f = ntfs_lock_new_page(mapping, index, gfp_mask);
+		if (IS_ERR(f)) {
+			err = PTR_ERR(f);
 			goto out1;
 		}
-		pages[i] = pg;
+		pages[i] = &f->page;
 	}
 
 	err = ni_read_frame(ni, frame_vbo, pages, pages_per_frame, 0);
Signature · 1 line
2.43.0
#1 lore raw
kernel test robot noticed the following build errors:

Hi Sun,

kernel test robot noticed the following build errors:

[auto build test ERROR on brauner-vfs/vfs.all]
[also build test ERROR on linus/master v6.19-rc8]
[cannot apply to next-20260205]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Sun-Jian/fs-ntfs3-return-folios-from-ntfs_lock_new_page/20260205-175053
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all
patch link:    https://lore.kernel.org/r/20260205094934.10500-1-sun.jian.kdev%40gmail.com
patch subject: [PATCH] fs/ntfs3: return folios from ntfs_lock_new_page()
config: i386-randconfig-013-20260207 (https://download.01.org/0day-ci/archive/20260207/[email protected]/config)
compiler: gcc-12 (Debian 12.4.0-5) 12.4.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260207/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

fs/ntfs3/frecord.c: In function 'ni_decompress_file':

>> fs/ntfs3/frecord.c:2200:28: error: assignment to 'struct page *' from incompatible pointer type 'struct folio *' [-Werror=incompatible-pointer-types]
    2200 |                         pg = ntfs_lock_new_page(mapping, index, gfp_mask);
         |                            ^

cc1: some warnings being treated as errors

vim +2200 fs/ntfs3/frecord.c

4342306f0f0d5f Konstantin Komarov      2021-08-13  2133  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2134  #ifdef CONFIG_NTFS3_LZX_XPRESS
4342306f0f0d5f Konstantin Komarov      2021-08-13  2135  /*
e8b8e97f91b80f Kari Argillander        2021-08-03  2136   * ni_decompress_file - Decompress LZX/Xpress compressed file.
e8b8e97f91b80f Kari Argillander        2021-08-03  2137   *
e8b8e97f91b80f Kari Argillander        2021-08-03  2138   * Remove ATTR_DATA::WofCompressedData.
e8b8e97f91b80f Kari Argillander        2021-08-03  2139   * Remove ATTR_REPARSE.
4342306f0f0d5f Konstantin Komarov      2021-08-13  2140   */
4342306f0f0d5f Konstantin Komarov      2021-08-13  2141  int ni_decompress_file(struct ntfs_inode *ni)
4342306f0f0d5f Konstantin Komarov      2021-08-13  2142  {
4342306f0f0d5f Konstantin Komarov      2021-08-13  2143  	struct ntfs_sb_info *sbi = ni->mi.sbi;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2144  	struct inode *inode = &ni->vfs_inode;
4fd6c08a16d7f1 Konstantin Komarov      2024-01-26  2145  	loff_t i_size = i_size_read(inode);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2146  	struct address_space *mapping = inode->i_mapping;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2147  	gfp_t gfp_mask = mapping_gfp_mask(mapping);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2148  	struct page **pages = NULL;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2149  	struct ATTR_LIST_ENTRY *le;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2150  	struct ATTRIB *attr;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2151  	CLST vcn, cend, lcn, clen, end;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2152  	pgoff_t index;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2153  	u64 vbo;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2154  	u8 frame_bits;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2155  	u32 i, frame_size, pages_per_frame, bytes;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2156  	struct mft_inode *mi;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2157  	int err;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2158  
e8b8e97f91b80f Kari Argillander        2021-08-03  2159  	/* Clusters for decompressed data. */
4342306f0f0d5f Konstantin Komarov      2021-08-13  2160  	cend = bytes_to_cluster(sbi, i_size);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2161  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2162  	if (!i_size)
4342306f0f0d5f Konstantin Komarov      2021-08-13  2163  		goto remove_wof;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2164  
e8b8e97f91b80f Kari Argillander        2021-08-03  2165  	/* Check in advance. */
4342306f0f0d5f Konstantin Komarov      2021-08-13  2166  	if (cend > wnd_zeroes(&sbi->used.bitmap)) {
4342306f0f0d5f Konstantin Komarov      2021-08-13  2167  		err = -ENOSPC;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2168  		goto out;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2169  	}
4342306f0f0d5f Konstantin Komarov      2021-08-13  2170  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2171  	frame_bits = ni_ext_compress_bits(ni);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2172  	frame_size = 1u << frame_bits;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2173  	pages_per_frame = frame_size >> PAGE_SHIFT;
345482bc431f64 Kari Argillander        2021-08-24  2174  	pages = kcalloc(pages_per_frame, sizeof(struct page *), GFP_NOFS);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2175  	if (!pages) {
4342306f0f0d5f Konstantin Komarov      2021-08-13  2176  		err = -ENOMEM;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2177  		goto out;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2178  	}
4342306f0f0d5f Konstantin Komarov      2021-08-13  2179  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2180  	/*
e8b8e97f91b80f Kari Argillander        2021-08-03  2181  	 * Step 1: Decompress data and copy to new allocated clusters.
4342306f0f0d5f Konstantin Komarov      2021-08-13  2182  	 */
4342306f0f0d5f Konstantin Komarov      2021-08-13  2183  	index = 0;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2184  	for (vbo = 0; vbo < i_size; vbo += bytes) {
4342306f0f0d5f Konstantin Komarov      2021-08-13  2185  		bool new;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2186  
f35590ee26f572 Konstantin Komarov      2025-10-14  2187  		bytes = vbo + frame_size > i_size ? (i_size - vbo) : frame_size;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2188  		end = bytes_to_cluster(sbi, vbo + bytes);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2189  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2190  		for (vcn = vbo >> sbi->cluster_bits; vcn < end; vcn += clen) {
4342306f0f0d5f Konstantin Komarov      2021-08-13  2191  			err = attr_data_get_block(ni, vcn, cend - vcn, &lcn,
c380b52f6c5702 Konstantin Komarov      2022-10-07  2192  						  &clen, &new, false);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2193  			if (err)
4342306f0f0d5f Konstantin Komarov      2021-08-13  2194  				goto out;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2195  		}
4342306f0f0d5f Konstantin Komarov      2021-08-13  2196  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2197  		for (i = 0; i < pages_per_frame; i++, index++) {
4342306f0f0d5f Konstantin Komarov      2021-08-13  2198  			struct page *pg;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2199  
68f6bd128e75a0 Matthew Wilcox (Oracle  2025-07-18 @2200) 			pg = ntfs_lock_new_page(mapping, index, gfp_mask);
68f6bd128e75a0 Matthew Wilcox (Oracle  2025-07-18  2201) 			if (IS_ERR(pg)) {
4342306f0f0d5f Konstantin Komarov      2021-08-13  2202  				while (i--) {
4342306f0f0d5f Konstantin Komarov      2021-08-13  2203  					unlock_page(pages[i]);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2204  					put_page(pages[i]);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2205  				}
68f6bd128e75a0 Matthew Wilcox (Oracle  2025-07-18  2206) 				err = PTR_ERR(pg);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2207  				goto out;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2208  			}
4342306f0f0d5f Konstantin Komarov      2021-08-13  2209  			pages[i] = pg;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2210  		}
4342306f0f0d5f Konstantin Komarov      2021-08-13  2211  
f35590ee26f572 Konstantin Komarov      2025-10-14  2212  		err = ni_read_frame(ni, vbo, pages, pages_per_frame, 1);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2213  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2214  		for (i = 0; i < pages_per_frame; i++) {
4342306f0f0d5f Konstantin Komarov      2021-08-13  2215  			unlock_page(pages[i]);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2216  			put_page(pages[i]);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2217  		}
4342306f0f0d5f Konstantin Komarov      2021-08-13  2218  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2219  		if (err)
4342306f0f0d5f Konstantin Komarov      2021-08-13  2220  			goto out;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2221  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2222  		cond_resched();
4342306f0f0d5f Konstantin Komarov      2021-08-13  2223  	}
4342306f0f0d5f Konstantin Komarov      2021-08-13  2224  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2225  remove_wof:
4342306f0f0d5f Konstantin Komarov      2021-08-13  2226  	/*
e8b8e97f91b80f Kari Argillander        2021-08-03  2227  	 * Step 2: Deallocate attributes ATTR_DATA::WofCompressedData
e8b8e97f91b80f Kari Argillander        2021-08-03  2228  	 * and ATTR_REPARSE.
4342306f0f0d5f Konstantin Komarov      2021-08-13  2229  	 */
4342306f0f0d5f Konstantin Komarov      2021-08-13  2230  	attr = NULL;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2231  	le = NULL;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2232  	while ((attr = ni_enum_attr_ex(ni, attr, &le, NULL))) {
4342306f0f0d5f Konstantin Komarov      2021-08-13  2233  		CLST svcn, evcn;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2234  		u32 asize, roff;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2235  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2236  		if (attr->type == ATTR_REPARSE) {
4342306f0f0d5f Konstantin Komarov      2021-08-13  2237  			struct MFT_REF ref;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2238  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2239  			mi_get_ref(&ni->mi, &ref);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2240  			ntfs_remove_reparse(sbi, 0, &ref);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2241  		}
4342306f0f0d5f Konstantin Komarov      2021-08-13  2242  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2243  		if (!attr->non_res)
4342306f0f0d5f Konstantin Komarov      2021-08-13  2244  			continue;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2245  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2246  		if (attr->type != ATTR_REPARSE &&
4342306f0f0d5f Konstantin Komarov      2021-08-13  2247  		    (attr->type != ATTR_DATA ||
4342306f0f0d5f Konstantin Komarov      2021-08-13  2248  		     attr->name_len != ARRAY_SIZE(WOF_NAME) ||
4342306f0f0d5f Konstantin Komarov      2021-08-13  2249  		     memcmp(attr_name(attr), WOF_NAME, sizeof(WOF_NAME))))
4342306f0f0d5f Konstantin Komarov      2021-08-13  2250  			continue;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2251  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2252  		svcn = le64_to_cpu(attr->nres.svcn);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2253  		evcn = le64_to_cpu(attr->nres.evcn);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2254  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2255  		if (evcn + 1 <= svcn)
4342306f0f0d5f Konstantin Komarov      2021-08-13  2256  			continue;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2257  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2258  		asize = le32_to_cpu(attr->size);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2259  		roff = le16_to_cpu(attr->nres.run_off);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2260  
6db620863f8528 Edward Lo               2022-08-06  2261  		if (roff > asize) {
6db620863f8528 Edward Lo               2022-08-06  2262  			err = -EINVAL;
6db620863f8528 Edward Lo               2022-08-06  2263  			goto out;
6db620863f8528 Edward Lo               2022-08-06  2264  		}
6db620863f8528 Edward Lo               2022-08-06  2265  
e8b8e97f91b80f Kari Argillander        2021-08-03  2266  		/*run==1  Means unpack and deallocate. */
4342306f0f0d5f Konstantin Komarov      2021-08-13  2267  		run_unpack_ex(RUN_DEALLOCATE, sbi, ni->mi.rno, svcn, evcn, svcn,
4342306f0f0d5f Konstantin Komarov      2021-08-13  2268  			      Add2Ptr(attr, roff), asize - roff);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2269  	}
4342306f0f0d5f Konstantin Komarov      2021-08-13  2270  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2271  	/*
e8b8e97f91b80f Kari Argillander        2021-08-03  2272  	 * Step 3: Remove attribute ATTR_DATA::WofCompressedData.
4342306f0f0d5f Konstantin Komarov      2021-08-13  2273  	 */
4342306f0f0d5f Konstantin Komarov      2021-08-13  2274  	err = ni_remove_attr(ni, ATTR_DATA, WOF_NAME, ARRAY_SIZE(WOF_NAME),
4342306f0f0d5f Konstantin Komarov      2021-08-13  2275  			     false, NULL);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2276  	if (err)
4342306f0f0d5f Konstantin Komarov      2021-08-13  2277  		goto out;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2278  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2279  	/*
e8b8e97f91b80f Kari Argillander        2021-08-03  2280  	 * Step 4: Remove ATTR_REPARSE.
4342306f0f0d5f Konstantin Komarov      2021-08-13  2281  	 */
4342306f0f0d5f Konstantin Komarov      2021-08-13  2282  	err = ni_remove_attr(ni, ATTR_REPARSE, NULL, 0, false, NULL);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2283  	if (err)
4342306f0f0d5f Konstantin Komarov      2021-08-13  2284  		goto out;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2285  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2286  	/*
e8b8e97f91b80f Kari Argillander        2021-08-03  2287  	 * Step 5: Remove sparse flag from data attribute.
4342306f0f0d5f Konstantin Komarov      2021-08-13  2288  	 */
4342306f0f0d5f Konstantin Komarov      2021-08-13  2289  	attr = ni_find_attr(ni, NULL, NULL, ATTR_DATA, NULL, 0, NULL, &mi);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2290  	if (!attr) {
4342306f0f0d5f Konstantin Komarov      2021-08-13  2291  		err = -EINVAL;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2292  		goto out;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2293  	}
4342306f0f0d5f Konstantin Komarov      2021-08-13  2294  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2295  	if (attr->non_res && is_attr_sparsed(attr)) {
d3624466b56dd5 Konstantin Komarov      2021-08-31  2296  		/* Sparsed attribute header is 8 bytes bigger than normal. */
4342306f0f0d5f Konstantin Komarov      2021-08-13  2297  		struct MFT_REC *rec = mi->mrec;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2298  		u32 used = le32_to_cpu(rec->used);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2299  		u32 asize = le32_to_cpu(attr->size);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2300  		u16 roff = le16_to_cpu(attr->nres.run_off);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2301  		char *rbuf = Add2Ptr(attr, roff);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2302  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2303  		memmove(rbuf - 8, rbuf, used - PtrOffset(rec, rbuf));
4342306f0f0d5f Konstantin Komarov      2021-08-13  2304  		attr->size = cpu_to_le32(asize - 8);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2305  		attr->flags &= ~ATTR_FLAG_SPARSED;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2306  		attr->nres.run_off = cpu_to_le16(roff - 8);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2307  		attr->nres.c_unit = 0;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2308  		rec->used = cpu_to_le32(used - 8);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2309  		mi->dirty = true;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2310  		ni->std_fa &= ~(FILE_ATTRIBUTE_SPARSE_FILE |
4342306f0f0d5f Konstantin Komarov      2021-08-13  2311  				FILE_ATTRIBUTE_REPARSE_POINT);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2312  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2313  		mark_inode_dirty(inode);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2314  	}
4342306f0f0d5f Konstantin Komarov      2021-08-13  2315  
e8b8e97f91b80f Kari Argillander        2021-08-03  2316  	/* Clear cached flag. */
4342306f0f0d5f Konstantin Komarov      2021-08-13  2317  	ni->ni_flags &= ~NI_FLAG_COMPRESSED_MASK;
c091354d6bf60e Matthew Wilcox (Oracle  2024-04-22  2318) 	if (ni->file.offs_folio) {
c091354d6bf60e Matthew Wilcox (Oracle  2024-04-22  2319) 		folio_put(ni->file.offs_folio);
c091354d6bf60e Matthew Wilcox (Oracle  2024-04-22  2320) 		ni->file.offs_folio = NULL;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2321  	}
4342306f0f0d5f Konstantin Komarov      2021-08-13  2322  	mapping->a_ops = &ntfs_aops;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2323  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2324  out:
195c52bdd5d5ec Kari Argillander        2021-08-24  2325  	kfree(pages);
c12df45ee69011 Konstantin Komarov      2022-07-13  2326  	if (err)
c12df45ee69011 Konstantin Komarov      2022-07-13  2327  		_ntfs_bad_inode(inode);
4342306f0f0d5f Konstantin Komarov      2021-08-13  2328  
4342306f0f0d5f Konstantin Komarov      2021-08-13  2329  	return err;
4342306f0f0d5f Konstantin Komarov      2021-08-13  2330  }
4342306f0f0d5f Konstantin Komarov      2021-08-13  2331  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#2 lore raw
In reply to Sun Jian
kernel test robot noticed the following build errors:

Hi Sun,

kernel test robot noticed the following build errors:

[auto build test ERROR on brauner-vfs/vfs.all]
[also build test ERROR on linus/master v6.19-rc8]
[cannot apply to next-20260205]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Sun-Jian/fs-ntfs3-return-folios-from-ntfs_lock_new_page/20260205-175053
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all
patch link:    https://lore.kernel.org/r/20260205094934.10500-1-sun.jian.kdev%40gmail.com
patch subject: [PATCH] fs/ntfs3: return folios from ntfs_lock_new_page()
config: hexagon-randconfig-001-20260207 (https://download.01.org/0day-ci/archive/20260207/[email protected]/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 9b8addffa70cee5b2acc5454712d9cf78ce45710)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260207/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> fs/ntfs3/frecord.c:2200:7: error: incompatible pointer types assigning to 'struct page *' from 'struct folio *' [-Wincompatible-pointer-types]
    2200 |                         pg = ntfs_lock_new_page(mapping, index, gfp_mask);
         |                            ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1 error generated.

vim +2200 fs/ntfs3/frecord.c

4342306f0f0d5ff Konstantin Komarov      2021-08-13  2133  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2134  #ifdef CONFIG_NTFS3_LZX_XPRESS
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2135  /*
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2136   * ni_decompress_file - Decompress LZX/Xpress compressed file.
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2137   *
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2138   * Remove ATTR_DATA::WofCompressedData.
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2139   * Remove ATTR_REPARSE.
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2140   */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2141  int ni_decompress_file(struct ntfs_inode *ni)
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2142  {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2143  	struct ntfs_sb_info *sbi = ni->mi.sbi;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2144  	struct inode *inode = &ni->vfs_inode;
4fd6c08a16d7f1b Konstantin Komarov      2024-01-26  2145  	loff_t i_size = i_size_read(inode);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2146  	struct address_space *mapping = inode->i_mapping;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2147  	gfp_t gfp_mask = mapping_gfp_mask(mapping);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2148  	struct page **pages = NULL;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2149  	struct ATTR_LIST_ENTRY *le;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2150  	struct ATTRIB *attr;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2151  	CLST vcn, cend, lcn, clen, end;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2152  	pgoff_t index;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2153  	u64 vbo;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2154  	u8 frame_bits;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2155  	u32 i, frame_size, pages_per_frame, bytes;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2156  	struct mft_inode *mi;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2157  	int err;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2158  
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2159  	/* Clusters for decompressed data. */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2160  	cend = bytes_to_cluster(sbi, i_size);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2161  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2162  	if (!i_size)
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2163  		goto remove_wof;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2164  
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2165  	/* Check in advance. */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2166  	if (cend > wnd_zeroes(&sbi->used.bitmap)) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2167  		err = -ENOSPC;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2168  		goto out;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2169  	}
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2170  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2171  	frame_bits = ni_ext_compress_bits(ni);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2172  	frame_size = 1u << frame_bits;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2173  	pages_per_frame = frame_size >> PAGE_SHIFT;
345482bc431f649 Kari Argillander        2021-08-24  2174  	pages = kcalloc(pages_per_frame, sizeof(struct page *), GFP_NOFS);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2175  	if (!pages) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2176  		err = -ENOMEM;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2177  		goto out;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2178  	}
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2179  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2180  	/*
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2181  	 * Step 1: Decompress data and copy to new allocated clusters.
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2182  	 */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2183  	index = 0;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2184  	for (vbo = 0; vbo < i_size; vbo += bytes) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2185  		bool new;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2186  
f35590ee26f5722 Konstantin Komarov      2025-10-14  2187  		bytes = vbo + frame_size > i_size ? (i_size - vbo) : frame_size;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2188  		end = bytes_to_cluster(sbi, vbo + bytes);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2189  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2190  		for (vcn = vbo >> sbi->cluster_bits; vcn < end; vcn += clen) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2191  			err = attr_data_get_block(ni, vcn, cend - vcn, &lcn,
c380b52f6c5702c Konstantin Komarov      2022-10-07  2192  						  &clen, &new, false);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2193  			if (err)
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2194  				goto out;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2195  		}
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2196  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2197  		for (i = 0; i < pages_per_frame; i++, index++) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2198  			struct page *pg;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2199  
68f6bd128e75a03 Matthew Wilcox (Oracle  2025-07-18 @2200) 			pg = ntfs_lock_new_page(mapping, index, gfp_mask);
68f6bd128e75a03 Matthew Wilcox (Oracle  2025-07-18  2201) 			if (IS_ERR(pg)) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2202  				while (i--) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2203  					unlock_page(pages[i]);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2204  					put_page(pages[i]);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2205  				}
68f6bd128e75a03 Matthew Wilcox (Oracle  2025-07-18  2206) 				err = PTR_ERR(pg);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2207  				goto out;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2208  			}
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2209  			pages[i] = pg;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2210  		}
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2211  
f35590ee26f5722 Konstantin Komarov      2025-10-14  2212  		err = ni_read_frame(ni, vbo, pages, pages_per_frame, 1);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2213  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2214  		for (i = 0; i < pages_per_frame; i++) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2215  			unlock_page(pages[i]);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2216  			put_page(pages[i]);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2217  		}
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2218  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2219  		if (err)
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2220  			goto out;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2221  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2222  		cond_resched();
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2223  	}
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2224  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2225  remove_wof:
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2226  	/*
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2227  	 * Step 2: Deallocate attributes ATTR_DATA::WofCompressedData
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2228  	 * and ATTR_REPARSE.
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2229  	 */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2230  	attr = NULL;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2231  	le = NULL;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2232  	while ((attr = ni_enum_attr_ex(ni, attr, &le, NULL))) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2233  		CLST svcn, evcn;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2234  		u32 asize, roff;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2235  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2236  		if (attr->type == ATTR_REPARSE) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2237  			struct MFT_REF ref;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2238  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2239  			mi_get_ref(&ni->mi, &ref);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2240  			ntfs_remove_reparse(sbi, 0, &ref);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2241  		}
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2242  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2243  		if (!attr->non_res)
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2244  			continue;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2245  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2246  		if (attr->type != ATTR_REPARSE &&
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2247  		    (attr->type != ATTR_DATA ||
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2248  		     attr->name_len != ARRAY_SIZE(WOF_NAME) ||
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2249  		     memcmp(attr_name(attr), WOF_NAME, sizeof(WOF_NAME))))
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2250  			continue;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2251  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2252  		svcn = le64_to_cpu(attr->nres.svcn);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2253  		evcn = le64_to_cpu(attr->nres.evcn);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2254  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2255  		if (evcn + 1 <= svcn)
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2256  			continue;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2257  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2258  		asize = le32_to_cpu(attr->size);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2259  		roff = le16_to_cpu(attr->nres.run_off);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2260  
6db620863f8528e Edward Lo               2022-08-06  2261  		if (roff > asize) {
6db620863f8528e Edward Lo               2022-08-06  2262  			err = -EINVAL;
6db620863f8528e Edward Lo               2022-08-06  2263  			goto out;
6db620863f8528e Edward Lo               2022-08-06  2264  		}
6db620863f8528e Edward Lo               2022-08-06  2265  
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2266  		/*run==1  Means unpack and deallocate. */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2267  		run_unpack_ex(RUN_DEALLOCATE, sbi, ni->mi.rno, svcn, evcn, svcn,
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2268  			      Add2Ptr(attr, roff), asize - roff);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2269  	}
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2270  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2271  	/*
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2272  	 * Step 3: Remove attribute ATTR_DATA::WofCompressedData.
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2273  	 */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2274  	err = ni_remove_attr(ni, ATTR_DATA, WOF_NAME, ARRAY_SIZE(WOF_NAME),
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2275  			     false, NULL);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2276  	if (err)
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2277  		goto out;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2278  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2279  	/*
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2280  	 * Step 4: Remove ATTR_REPARSE.
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2281  	 */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2282  	err = ni_remove_attr(ni, ATTR_REPARSE, NULL, 0, false, NULL);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2283  	if (err)
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2284  		goto out;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2285  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2286  	/*
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2287  	 * Step 5: Remove sparse flag from data attribute.
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2288  	 */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2289  	attr = ni_find_attr(ni, NULL, NULL, ATTR_DATA, NULL, 0, NULL, &mi);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2290  	if (!attr) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2291  		err = -EINVAL;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2292  		goto out;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2293  	}
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2294  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2295  	if (attr->non_res && is_attr_sparsed(attr)) {
d3624466b56dd5b Konstantin Komarov      2021-08-31  2296  		/* Sparsed attribute header is 8 bytes bigger than normal. */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2297  		struct MFT_REC *rec = mi->mrec;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2298  		u32 used = le32_to_cpu(rec->used);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2299  		u32 asize = le32_to_cpu(attr->size);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2300  		u16 roff = le16_to_cpu(attr->nres.run_off);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2301  		char *rbuf = Add2Ptr(attr, roff);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2302  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2303  		memmove(rbuf - 8, rbuf, used - PtrOffset(rec, rbuf));
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2304  		attr->size = cpu_to_le32(asize - 8);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2305  		attr->flags &= ~ATTR_FLAG_SPARSED;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2306  		attr->nres.run_off = cpu_to_le16(roff - 8);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2307  		attr->nres.c_unit = 0;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2308  		rec->used = cpu_to_le32(used - 8);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2309  		mi->dirty = true;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2310  		ni->std_fa &= ~(FILE_ATTRIBUTE_SPARSE_FILE |
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2311  				FILE_ATTRIBUTE_REPARSE_POINT);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2312  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2313  		mark_inode_dirty(inode);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2314  	}
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2315  
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2316  	/* Clear cached flag. */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2317  	ni->ni_flags &= ~NI_FLAG_COMPRESSED_MASK;
c091354d6bf60ec Matthew Wilcox (Oracle  2024-04-22  2318) 	if (ni->file.offs_folio) {
c091354d6bf60ec Matthew Wilcox (Oracle  2024-04-22  2319) 		folio_put(ni->file.offs_folio);
c091354d6bf60ec Matthew Wilcox (Oracle  2024-04-22  2320) 		ni->file.offs_folio = NULL;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2321  	}
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2322  	mapping->a_ops = &ntfs_aops;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2323  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2324  out:
195c52bdd5d5ecf Kari Argillander        2021-08-24  2325  	kfree(pages);
c12df45ee690112 Konstantin Komarov      2022-07-13  2326  	if (err)
c12df45ee690112 Konstantin Komarov      2022-07-13  2327  		_ntfs_bad_inode(inode);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2328  
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2329  	return err;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2330  }
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2331  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author
#3 lore raw

Hi,
Thanks for your reports! v2 has been sent to fix the issue in ni_decompress_file().
Message-ID: [email protected] Regards,
sun jian

Quoted 238 lines · kernel test robot

Hi Sun,

kernel test robot noticed the following build errors:

[auto build test ERROR on brauner-vfs/vfs.all]
[also build test ERROR on linus/master v6.19-rc8]
[cannot apply to next-20260205]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Sun-Jian/fs-ntfs3-return-folios-from-ntfs_lock_new_page/20260205-175053
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all
patch link:    https://lore.kernel.org/r/20260205094934.10500-1-sun.jian.kdev%40gmail.com
patch subject: [PATCH] fs/ntfs3: return folios from ntfs_lock_new_page()
config: hexagon-randconfig-001-20260207 (https://download.01.org/0day-ci/archive/20260207/[email protected]/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 9b8addffa70cee5b2acc5454712d9cf78ce45710)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260207/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

fs/ntfs3/frecord.c:2200:7: error: incompatible pointer types assigning to 'struct page *' from 'struct folio *' [-Wincompatible-pointer-types]

    2200 |                         pg = ntfs_lock_new_page(mapping, index, gfp_mask);
         |                            ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1 error generated.

vim +2200 fs/ntfs3/frecord.c

4342306f0f0d5ff Konstantin Komarov      2021-08-13  2133
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2134  #ifdef CONFIG_NTFS3_LZX_XPRESS
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2135  /*
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2136   * ni_decompress_file - Decompress LZX/Xpress compressed file.
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2137   *
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2138   * Remove ATTR_DATA::WofCompressedData.
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2139   * Remove ATTR_REPARSE.
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2140   */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2141  int ni_decompress_file(struct ntfs_inode *ni)
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2142  {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2143        struct ntfs_sb_info *sbi = ni->mi.sbi;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2144        struct inode *inode = &ni->vfs_inode;
4fd6c08a16d7f1b Konstantin Komarov      2024-01-26  2145        loff_t i_size = i_size_read(inode);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2146        struct address_space *mapping = inode->i_mapping;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2147        gfp_t gfp_mask = mapping_gfp_mask(mapping);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2148        struct page **pages = NULL;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2149        struct ATTR_LIST_ENTRY *le;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2150        struct ATTRIB *attr;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2151        CLST vcn, cend, lcn, clen, end;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2152        pgoff_t index;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2153        u64 vbo;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2154        u8 frame_bits;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2155        u32 i, frame_size, pages_per_frame, bytes;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2156        struct mft_inode *mi;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2157        int err;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2158
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2159        /* Clusters for decompressed data. */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2160        cend = bytes_to_cluster(sbi, i_size);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2161
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2162        if (!i_size)
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2163                goto remove_wof;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2164
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2165        /* Check in advance. */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2166        if (cend > wnd_zeroes(&sbi->used.bitmap)) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2167                err = -ENOSPC;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2168                goto out;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2169        }
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2170
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2171        frame_bits = ni_ext_compress_bits(ni);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2172        frame_size = 1u << frame_bits;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2173        pages_per_frame = frame_size >> PAGE_SHIFT;
345482bc431f649 Kari Argillander        2021-08-24  2174        pages = kcalloc(pages_per_frame, sizeof(struct page *), GFP_NOFS);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2175        if (!pages) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2176                err = -ENOMEM;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2177                goto out;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2178        }
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2179
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2180        /*
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2181         * Step 1: Decompress data and copy to new allocated clusters.
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2182         */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2183        index = 0;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2184        for (vbo = 0; vbo < i_size; vbo += bytes) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2185                bool new;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2186
f35590ee26f5722 Konstantin Komarov      2025-10-14  2187                bytes = vbo + frame_size > i_size ? (i_size - vbo) : frame_size;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2188                end = bytes_to_cluster(sbi, vbo + bytes);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2189
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2190                for (vcn = vbo >> sbi->cluster_bits; vcn < end; vcn += clen) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2191                        err = attr_data_get_block(ni, vcn, cend - vcn, &lcn,
c380b52f6c5702c Konstantin Komarov      2022-10-07  2192                                                  &clen, &new, false);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2193                        if (err)
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2194                                goto out;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2195                }
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2196
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2197                for (i = 0; i < pages_per_frame; i++, index++) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2198                        struct page *pg;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2199
68f6bd128e75a03 Matthew Wilcox (Oracle  2025-07-18 @2200)                       pg = ntfs_lock_new_page(mapping, index, gfp_mask);
68f6bd128e75a03 Matthew Wilcox (Oracle  2025-07-18  2201)                       if (IS_ERR(pg)) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2202                                while (i--) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2203                                        unlock_page(pages[i]);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2204                                        put_page(pages[i]);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2205                                }
68f6bd128e75a03 Matthew Wilcox (Oracle  2025-07-18  2206)                               err = PTR_ERR(pg);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2207                                goto out;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2208                        }
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2209                        pages[i] = pg;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2210                }
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2211
f35590ee26f5722 Konstantin Komarov      2025-10-14  2212                err = ni_read_frame(ni, vbo, pages, pages_per_frame, 1);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2213
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2214                for (i = 0; i < pages_per_frame; i++) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2215                        unlock_page(pages[i]);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2216                        put_page(pages[i]);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2217                }
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2218
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2219                if (err)
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2220                        goto out;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2221
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2222                cond_resched();
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2223        }
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2224
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2225  remove_wof:
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2226        /*
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2227         * Step 2: Deallocate attributes ATTR_DATA::WofCompressedData
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2228         * and ATTR_REPARSE.
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2229         */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2230        attr = NULL;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2231        le = NULL;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2232        while ((attr = ni_enum_attr_ex(ni, attr, &le, NULL))) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2233                CLST svcn, evcn;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2234                u32 asize, roff;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2235
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2236                if (attr->type == ATTR_REPARSE) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2237                        struct MFT_REF ref;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2238
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2239                        mi_get_ref(&ni->mi, &ref);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2240                        ntfs_remove_reparse(sbi, 0, &ref);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2241                }
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2242
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2243                if (!attr->non_res)
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2244                        continue;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2245
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2246                if (attr->type != ATTR_REPARSE &&
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2247                    (attr->type != ATTR_DATA ||
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2248                     attr->name_len != ARRAY_SIZE(WOF_NAME) ||
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2249                     memcmp(attr_name(attr), WOF_NAME, sizeof(WOF_NAME))))
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2250                        continue;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2251
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2252                svcn = le64_to_cpu(attr->nres.svcn);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2253                evcn = le64_to_cpu(attr->nres.evcn);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2254
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2255                if (evcn + 1 <= svcn)
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2256                        continue;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2257
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2258                asize = le32_to_cpu(attr->size);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2259                roff = le16_to_cpu(attr->nres.run_off);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2260
6db620863f8528e Edward Lo               2022-08-06  2261                if (roff > asize) {
6db620863f8528e Edward Lo               2022-08-06  2262                        err = -EINVAL;
6db620863f8528e Edward Lo               2022-08-06  2263                        goto out;
6db620863f8528e Edward Lo               2022-08-06  2264                }
6db620863f8528e Edward Lo               2022-08-06  2265
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2266                /*run==1  Means unpack and deallocate. */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2267                run_unpack_ex(RUN_DEALLOCATE, sbi, ni->mi.rno, svcn, evcn, svcn,
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2268                              Add2Ptr(attr, roff), asize - roff);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2269        }
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2270
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2271        /*
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2272         * Step 3: Remove attribute ATTR_DATA::WofCompressedData.
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2273         */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2274        err = ni_remove_attr(ni, ATTR_DATA, WOF_NAME, ARRAY_SIZE(WOF_NAME),
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2275                             false, NULL);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2276        if (err)
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2277                goto out;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2278
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2279        /*
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2280         * Step 4: Remove ATTR_REPARSE.
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2281         */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2282        err = ni_remove_attr(ni, ATTR_REPARSE, NULL, 0, false, NULL);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2283        if (err)
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2284                goto out;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2285
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2286        /*
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2287         * Step 5: Remove sparse flag from data attribute.
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2288         */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2289        attr = ni_find_attr(ni, NULL, NULL, ATTR_DATA, NULL, 0, NULL, &mi);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2290        if (!attr) {
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2291                err = -EINVAL;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2292                goto out;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2293        }
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2294
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2295        if (attr->non_res && is_attr_sparsed(attr)) {
d3624466b56dd5b Konstantin Komarov      2021-08-31  2296                /* Sparsed attribute header is 8 bytes bigger than normal. */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2297                struct MFT_REC *rec = mi->mrec;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2298                u32 used = le32_to_cpu(rec->used);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2299                u32 asize = le32_to_cpu(attr->size);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2300                u16 roff = le16_to_cpu(attr->nres.run_off);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2301                char *rbuf = Add2Ptr(attr, roff);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2302
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2303                memmove(rbuf - 8, rbuf, used - PtrOffset(rec, rbuf));
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2304                attr->size = cpu_to_le32(asize - 8);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2305                attr->flags &= ~ATTR_FLAG_SPARSED;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2306                attr->nres.run_off = cpu_to_le16(roff - 8);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2307                attr->nres.c_unit = 0;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2308                rec->used = cpu_to_le32(used - 8);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2309                mi->dirty = true;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2310                ni->std_fa &= ~(FILE_ATTRIBUTE_SPARSE_FILE |
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2311                                FILE_ATTRIBUTE_REPARSE_POINT);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2312
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2313                mark_inode_dirty(inode);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2314        }
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2315
e8b8e97f91b80f0 Kari Argillander        2021-08-03  2316        /* Clear cached flag. */
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2317        ni->ni_flags &= ~NI_FLAG_COMPRESSED_MASK;
c091354d6bf60ec Matthew Wilcox (Oracle  2024-04-22  2318)       if (ni->file.offs_folio) {
c091354d6bf60ec Matthew Wilcox (Oracle  2024-04-22  2319)               folio_put(ni->file.offs_folio);
c091354d6bf60ec Matthew Wilcox (Oracle  2024-04-22  2320)               ni->file.offs_folio = NULL;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2321        }
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2322        mapping->a_ops = &ntfs_aops;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2323
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2324  out:
195c52bdd5d5ecf Kari Argillander        2021-08-24  2325        kfree(pages);
c12df45ee690112 Konstantin Komarov      2022-07-13  2326        if (err)
c12df45ee690112 Konstantin Komarov      2022-07-13  2327                _ntfs_bad_inode(inode);
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2328
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2329        return err;
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2330  }
4342306f0f0d5ff Konstantin Komarov      2021-08-13  2331

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

author
#4 lore raw

PATCH v2 1/1 fs/ntfs3: return folios from ntfs_lock_new_page()

In reply to Sun Jian

ntfs_lock_new_page() currently returns a struct page * but it primarily operates on folios via __filemap_get_folio(). Convert it to return a struct folio * and use folio_alloc() + __folio_set_locked() for the temporary page used to avoid data corruption during decompression.

When the cached folio is not uptodate, preserve the existing behavior by using folio_file_page() and converting the returned page back to a folio.

Update ni_readpage_cmpr() and ni_decompress_file() to handle the new return type while keeping the existing struct page * array and the unlock_page()/put_page() cleanup paths unchanged.

---
v2:
- Fix build failure in ni_decompress_file() by switching the local pointer to struct folio * (reported by kernel test robot).
- Reported-by: kernel test robot <[email protected]>
- Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
- Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

 fs/ntfs3/frecord.c | 43 ++++++++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 19 deletions(-)
fs/ntfs3/frecord.c +24 -19
index 641ddaf8d4a0..6169257cf784 100644
@@ -2022,27 +2022,31 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_extent_info *fieinfo,
 	return err;
 }
 
-static struct page *ntfs_lock_new_page(struct address_space *mapping,
-		pgoff_t index, gfp_t gfp)
+static struct folio *ntfs_lock_new_page(struct address_space *mapping,
+					pgoff_t index, gfp_t gfp)
 {
 	struct folio *folio = __filemap_get_folio(mapping, index,
 			FGP_LOCK | FGP_ACCESSED | FGP_CREAT, gfp);
-	struct page *page;
 
 	if (IS_ERR(folio))
-		return ERR_CAST(folio);
+		return folio;
 
-	if (!folio_test_uptodate(folio))
-		return folio_file_page(folio, index);
+	if (!folio_test_uptodate(folio)) {
+		struct page *page = folio_file_page(folio, index);
+
+		if (IS_ERR(page))
+			return ERR_CAST(page);
+		return page_folio(page);
+	}
 
 	/* Use a temporary page to avoid data corruption */
 	folio_unlock(folio);
 	folio_put(folio);
-	page = alloc_page(gfp);
-	if (!page)
+	folio = folio_alloc(gfp, 0);
+	if (!folio)
 		return ERR_PTR(-ENOMEM);
-	__SetPageLocked(page);
-	return page;
+	__folio_set_locked(folio);
+	return folio;
 }
 
 /*
@@ -2064,6 +2068,7 @@ int ni_readpage_cmpr(struct ntfs_inode *ni, struct folio *folio)
 	u32 i, idx, frame_size, pages_per_frame;
 	gfp_t gfp_mask;
 	struct page *pg;
+	struct folio *f;
 
 	if (vbo >= i_size_read(&ni->vfs_inode)) {
 		folio_zero_range(folio, 0, folio_size(folio));
@@ -2099,12 +2104,12 @@ int ni_readpage_cmpr(struct ntfs_inode *ni, struct folio *folio)
 		if (i == idx)
 			continue;
 
-		pg = ntfs_lock_new_page(mapping, index, gfp_mask);
-		if (IS_ERR(pg)) {
-			err = PTR_ERR(pg);
+		f = ntfs_lock_new_page(mapping, index, gfp_mask);
+		if (IS_ERR(f)) {
+			err = PTR_ERR(f);
 			goto out1;
 		}
-		pages[i] = pg;
+		pages[i] = &f->page;
 	}
 
 	err = ni_read_frame(ni, frame_vbo, pages, pages_per_frame, 0);
@@ -2190,18 +2195,18 @@ int ni_decompress_file(struct ntfs_inode *ni)
 		}
 
 		for (i = 0; i < pages_per_frame; i++, index++) {
-			struct page *pg;
+			struct folio *f;
 
-			pg = ntfs_lock_new_page(mapping, index, gfp_mask);
-			if (IS_ERR(pg)) {
+			f = ntfs_lock_new_page(mapping, index, gfp_mask);
+			if (IS_ERR(f)) {
 				while (i--) {
 					unlock_page(pages[i]);
 					put_page(pages[i]);
 				}
-				err = PTR_ERR(pg);
+				err = PTR_ERR(f);
 				goto out;
 			}
-			pages[i] = pg;
+			pages[i] = &f->page;
 		}
 
 		err = ni_read_frame(ni, vbo, pages, pages_per_frame, 1);

base-commit: 2687c848e57820651b9f69d30c4710f4219f7dbf

Signature · 1 line
2.43.0
maintainer Applied
#5 lore raw
Quoted 121 lines · Sun Jian

ntfs_lock_new_page() currently returns a struct page * but it primarily operates on folios via __filemap_get_folio(). Convert it to return a struct folio * and use folio_alloc() + __folio_set_locked() for the temporary page used to avoid data corruption during decompression.

When the cached folio is not uptodate, preserve the existing behavior by using folio_file_page() and converting the returned page back to a folio.

Update ni_readpage_cmpr() and ni_decompress_file() to handle the new return type while keeping the existing struct page * array and the unlock_page()/put_page() cleanup paths unchanged.

---
v2:
- Fix build failure in ni_decompress_file() by switching the local pointer to struct folio * (reported by kernel test robot).
- Reported-by: kernel test robot <[email protected]>
- Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
- Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

  fs/ntfs3/frecord.c | 43 ++++++++++++++++++++++++-------------------
  1 file changed, 24 insertions(+), 19 deletions(-)
fs/ntfs3/frecord.c +24 -19
index 641ddaf8d4a0..6169257cf784 100644
@@ -2022,27 +2022,31 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_extent_info *fieinfo,
  	return err;
  }
 
-static struct page *ntfs_lock_new_page(struct address_space *mapping,
-		pgoff_t index, gfp_t gfp)
+static struct folio *ntfs_lock_new_page(struct address_space *mapping,
+					pgoff_t index, gfp_t gfp)
  {
  	struct folio *folio = __filemap_get_folio(mapping, index,
  			FGP_LOCK | FGP_ACCESSED | FGP_CREAT, gfp);
-	struct page *page;
 
  	if (IS_ERR(folio))
-		return ERR_CAST(folio);
+		return folio;
 
-	if (!folio_test_uptodate(folio))
-		return folio_file_page(folio, index);
+	if (!folio_test_uptodate(folio)) {
+		struct page *page = folio_file_page(folio, index);
+
+		if (IS_ERR(page))
+			return ERR_CAST(page);
+		return page_folio(page);
+	}
 
  	/* Use a temporary page to avoid data corruption */
  	folio_unlock(folio);
  	folio_put(folio);
-	page = alloc_page(gfp);
-	if (!page)
+	folio = folio_alloc(gfp, 0);
+	if (!folio)
  		return ERR_PTR(-ENOMEM);
-	__SetPageLocked(page);
-	return page;
+	__folio_set_locked(folio);
+	return folio;
  }
 
  /*
@@ -2064,6 +2068,7 @@ int ni_readpage_cmpr(struct ntfs_inode *ni, struct folio *folio)
  	u32 i, idx, frame_size, pages_per_frame;
  	gfp_t gfp_mask;
  	struct page *pg;
+	struct folio *f;
 
  	if (vbo >= i_size_read(&ni->vfs_inode)) {
  		folio_zero_range(folio, 0, folio_size(folio));
@@ -2099,12 +2104,12 @@ int ni_readpage_cmpr(struct ntfs_inode *ni, struct folio *folio)
  		if (i == idx)
  			continue;
 
-		pg = ntfs_lock_new_page(mapping, index, gfp_mask);
-		if (IS_ERR(pg)) {
-			err = PTR_ERR(pg);
+		f = ntfs_lock_new_page(mapping, index, gfp_mask);
+		if (IS_ERR(f)) {
+			err = PTR_ERR(f);
  			goto out1;
  		}
-		pages[i] = pg;
+		pages[i] = &f->page;
  	}
 
  	err = ni_read_frame(ni, frame_vbo, pages, pages_per_frame, 0);
@@ -2190,18 +2195,18 @@ int ni_decompress_file(struct ntfs_inode *ni)
  		}
 
  		for (i = 0; i < pages_per_frame; i++, index++) {
-			struct page *pg;
+			struct folio *f;
 
-			pg = ntfs_lock_new_page(mapping, index, gfp_mask);
-			if (IS_ERR(pg)) {
+			f = ntfs_lock_new_page(mapping, index, gfp_mask);
+			if (IS_ERR(f)) {
  				while (i--) {
  					unlock_page(pages[i]);
  					put_page(pages[i]);
  				}
-				err = PTR_ERR(pg);
+				err = PTR_ERR(f);
  				goto out;
  			}
-			pages[i] = pg;
+			pages[i] = &f->page;
  		}
 
  		err = ni_read_frame(ni, vbo, pages, pages_per_frame, 1);
Quoted 1 line

base-commit: 2687c848e57820651b9f69d30c4710f4219f7dbf

Hello,

Applied, thanks for the patch.

Regards,
Konstantin