Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2017-2018 HUAWEI, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *             https://www.huawei.com/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Created by Gao Xiang <gaoxiang25@huawei.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/prefetch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/uio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/iomap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/dax.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <trace/events/erofs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) static void erofs_readendio(struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	struct bio_vec *bvec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	blk_status_t err = bio->bi_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	struct bvec_iter_all iter_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	bio_for_each_segment_all(bvec, bio, iter_all) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 		struct page *page = bvec->bv_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 		/* page is already locked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 		DBG_BUGON(PageUptodate(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 			SetPageError(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 			SetPageUptodate(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		/* page could be reclaimed now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	bio_put(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct address_space *const mapping = sb->s_bdev->bd_inode->i_mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	page = read_cache_page_gfp(mapping, blkaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 				   mapping_gfp_constraint(mapping, ~__GFP_FS));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	/* should already be PageUptodate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if (!IS_ERR(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		lock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	return page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static int erofs_map_blocks_flatmode(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 				     struct erofs_map_blocks *map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 				     int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	erofs_blk_t nblocks, lastblk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	u64 offset = map->m_la;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct erofs_inode *vi = EROFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	bool tailendpacking = (vi->datalayout == EROFS_INODE_FLAT_INLINE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	trace_erofs_map_blocks_flatmode_enter(inode, map, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	nblocks = DIV_ROUND_UP(inode->i_size, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	lastblk = nblocks - tailendpacking;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (offset >= inode->i_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		/* leave out-of-bound access unmapped */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		map->m_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		map->m_plen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	/* there is no hole in flatmode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	map->m_flags = EROFS_MAP_MAPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (offset < blknr_to_addr(lastblk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		map->m_pa = blknr_to_addr(vi->raw_blkaddr) + map->m_la;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		map->m_plen = blknr_to_addr(lastblk) - offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	} else if (tailendpacking) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		/* 2 - inode inline B: inode, [xattrs], inline last blk... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		map->m_pa = iloc(sbi, vi->nid) + vi->inode_isize +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			vi->xattr_isize + erofs_blkoff(map->m_la);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		map->m_plen = inode->i_size - offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		/* inline data should be located in one meta block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		if (erofs_blkoff(map->m_pa) + map->m_plen > PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			erofs_err(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 				  "inline data cross block boundary @ nid %llu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 				  vi->nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			DBG_BUGON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			err = -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		map->m_flags |= EROFS_MAP_META;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		erofs_err(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			  "internal error @ nid: %llu (size %llu), m_la 0x%llx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			  vi->nid, inode->i_size, map->m_la);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		DBG_BUGON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	map->m_llen = map->m_plen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	trace_erofs_map_blocks_flatmode_exit(inode, map, flags, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static inline struct bio *erofs_read_raw_page(struct bio *bio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 					      struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 					      struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 					      erofs_off_t *last_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 					      unsigned int nblocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 					      bool ra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	struct inode *const inode = mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	struct super_block *const sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	erofs_off_t current_block = (erofs_off_t)page->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	DBG_BUGON(!nblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	if (PageUptodate(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		goto has_updated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	/* note that for readpage case, bio also equals to NULL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (bio &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	    /* not continuous */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	    *last_block + 1 != current_block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) submit_bio_retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		submit_bio(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		bio = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (!bio) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		struct erofs_map_blocks map = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			.m_la = blknr_to_addr(current_block),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		erofs_blk_t blknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		unsigned int blkoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		err = erofs_map_blocks_flatmode(inode, &map, EROFS_GET_BLOCKS_RAW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		/* zero out the holed page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		if (!(map.m_flags & EROFS_MAP_MAPPED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			zero_user_segment(page, 0, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			SetPageUptodate(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			/* imply err = 0, see erofs_map_blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			goto has_updated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		/* for RAW access mode, m_plen must be equal to m_llen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		DBG_BUGON(map.m_plen != map.m_llen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		blknr = erofs_blknr(map.m_pa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		blkoff = erofs_blkoff(map.m_pa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		/* deal with inline page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		if (map.m_flags & EROFS_MAP_META) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			void *vsrc, *vto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			struct page *ipage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			DBG_BUGON(map.m_plen > PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			ipage = erofs_get_meta_page(inode->i_sb, blknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			if (IS_ERR(ipage)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 				err = PTR_ERR(ipage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 				goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			vsrc = kmap_atomic(ipage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			vto = kmap_atomic(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			memcpy(vto, vsrc + blkoff, map.m_plen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 			memset(vto + map.m_plen, 0, PAGE_SIZE - map.m_plen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 			kunmap_atomic(vto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			kunmap_atomic(vsrc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			flush_dcache_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			SetPageUptodate(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			/* TODO: could we unlock the page earlier? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			unlock_page(ipage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			put_page(ipage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			/* imply err = 0, see erofs_map_blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			goto has_updated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		/* pa must be block-aligned for raw reading */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		DBG_BUGON(erofs_blkoff(map.m_pa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		/* max # of continuous pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		if (nblocks > DIV_ROUND_UP(map.m_plen, PAGE_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			nblocks = DIV_ROUND_UP(map.m_plen, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		if (nblocks > BIO_MAX_PAGES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			nblocks = BIO_MAX_PAGES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		bio = bio_alloc(GFP_NOIO, nblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		bio->bi_end_io = erofs_readendio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		bio_set_dev(bio, sb->s_bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		bio->bi_iter.bi_sector = (sector_t)blknr <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			LOG_SECTORS_PER_BLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		bio->bi_opf = REQ_OP_READ | (ra ? REQ_RAHEAD : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	err = bio_add_page(bio, page, PAGE_SIZE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	/* out of the extent or bio is full */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	if (err < PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		goto submit_bio_retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	*last_block = current_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	/* shift in advance in case of it followed by too many gaps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (bio->bi_iter.bi_size >= bio->bi_max_vecs * PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		/* err should reassign to 0 after submitting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		goto submit_bio_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	return bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	/* for sync reading, set page error immediately */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	if (!ra) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		SetPageError(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		ClearPageUptodate(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) has_updated:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	/* if updated manually, continuous pages has a gap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) submit_bio_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		submit_bio(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	return err ? ERR_PTR(err) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  * since we dont have write or truncate flows, so no inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  * locking needs to be held at the moment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static int erofs_raw_access_readpage(struct file *file, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	erofs_off_t last_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	trace_erofs_readpage(page, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	bio = erofs_read_raw_page(NULL, page->mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 				  page, &last_block, 1, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	if (IS_ERR(bio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		return PTR_ERR(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	DBG_BUGON(bio);	/* since we have only one bio -- must be NULL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static void erofs_raw_access_readahead(struct readahead_control *rac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	erofs_off_t last_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	struct bio *bio = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	trace_erofs_readpages(rac->mapping->host, readahead_index(rac),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			readahead_count(rac), true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	while ((page = readahead_page(rac))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		prefetchw(&page->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		bio = erofs_read_raw_page(bio, rac->mapping, page, &last_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 				readahead_count(rac), true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		/* all the page errors are ignored when readahead */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		if (IS_ERR(bio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			pr_err("%s, readahead error at page %lu of nid %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 			       __func__, page->index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			       EROFS_I(rac->mapping->host)->nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 			bio = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	/* the rare case (end in gaps) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	if (bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		submit_bio(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) static sector_t erofs_bmap(struct address_space *mapping, sector_t block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	struct inode *inode = mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	struct erofs_map_blocks map = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		.m_la = blknr_to_addr(block),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	if (EROFS_I(inode)->datalayout == EROFS_INODE_FLAT_INLINE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		erofs_blk_t blks = i_size_read(inode) >> LOG_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		if (block >> LOG_SECTORS_PER_BLOCK >= blks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	if (!erofs_map_blocks_flatmode(inode, &map, EROFS_GET_BLOCKS_RAW))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		return erofs_blknr(map.m_pa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		unsigned int flags, struct iomap *iomap, struct iomap *srcmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	struct erofs_map_blocks map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	map.m_la = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	map.m_llen = length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	ret = erofs_map_blocks_flatmode(inode, &map, EROFS_GET_BLOCKS_RAW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	iomap->bdev = inode->i_sb->s_bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	iomap->dax_dev = EROFS_I_SB(inode)->dax_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	iomap->offset = map.m_la;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	iomap->length = map.m_llen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	iomap->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	if (!(map.m_flags & EROFS_MAP_MAPPED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		iomap->type = IOMAP_HOLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		iomap->addr = IOMAP_NULL_ADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		if (!iomap->length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			iomap->length = length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	/* that shouldn't happen for now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	if (map.m_flags & EROFS_MAP_META) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		DBG_BUGON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		return -ENOTBLK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	iomap->type = IOMAP_MAPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	iomap->addr = map.m_pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) static const struct iomap_ops erofs_iomap_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	.iomap_begin = erofs_iomap_begin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) static int erofs_prepare_dio(struct kiocb *iocb, struct iov_iter *to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	struct inode *inode = file_inode(iocb->ki_filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	loff_t align = iocb->ki_pos | iov_iter_count(to) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		iov_iter_alignment(to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	struct block_device *bdev = inode->i_sb->s_bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	unsigned int blksize_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	if (bdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		blksize_mask = (1 << ilog2(bdev_logical_block_size(bdev))) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		blksize_mask = (1 << inode->i_blkbits) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	if (align & blksize_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	 * Temporarily fall back tail-packing inline to buffered I/O instead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	 * since tail-packing inline support relies on an iomap core update.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	if (EROFS_I(inode)->datalayout == EROFS_INODE_FLAT_INLINE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	    iocb->ki_pos + iov_iter_count(to) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 			rounddown(inode->i_size, EROFS_BLKSIZ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) static ssize_t erofs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	/* no need taking (shared) inode lock since it's a ro filesystem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	if (!iov_iter_count(to))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) #ifdef CONFIG_FS_DAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	if (IS_DAX(iocb->ki_filp->f_mapping->host))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		return dax_iomap_rw(iocb, to, &erofs_iomap_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	if (iocb->ki_flags & IOCB_DIRECT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		int err = erofs_prepare_dio(iocb, to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 			return iomap_dio_rw(iocb, to, &erofs_iomap_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 					    NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	return generic_file_buffered_read(iocb, to, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) /* for uncompressed (aligned) files and raw access for other files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) const struct address_space_operations erofs_raw_access_aops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	.readpage = erofs_raw_access_readpage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	.readahead = erofs_raw_access_readahead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	.bmap = erofs_bmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	.direct_IO = noop_direct_IO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) #ifdef CONFIG_FS_DAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) static vm_fault_t erofs_dax_huge_fault(struct vm_fault *vmf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		enum page_entry_size pe_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	return dax_iomap_fault(vmf, pe_size, NULL, NULL, &erofs_iomap_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static vm_fault_t erofs_dax_fault(struct vm_fault *vmf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	return erofs_dax_huge_fault(vmf, PE_SIZE_PTE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) static const struct vm_operations_struct erofs_dax_vm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	.fault		= erofs_dax_fault,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	.huge_fault	= erofs_dax_huge_fault,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static int erofs_file_mmap(struct file *file, struct vm_area_struct *vma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	if (!IS_DAX(file_inode(file)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		return generic_file_readonly_mmap(file, vma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	vma->vm_ops = &erofs_dax_vm_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	vma->vm_flags |= VM_HUGEPAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) #if defined(CONFIG_ROCKCHIP_RAMDISK) && defined(CONFIG_ARM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	vma->vm_flags |= VM_MIXEDMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) #define erofs_file_mmap	generic_file_readonly_mmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) const struct file_operations erofs_file_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	.llseek		= generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	.read_iter	= erofs_file_read_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	.mmap		= erofs_file_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	.splice_read	= generic_file_splice_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)