History

Merge tag 'f2fs-for-v5.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs

Pull f2fs updates from Jaegeuk Kim: "Another round of various bug fixes came in. Damien improved SMR drive support a bit, and Chao replaced BUG_ON() with reporting errors to user since we've not hit from users but did hit from crafted images. We've found a disk layout bug in large_nat_bits feature which supports very large NAT entries enabled at mkfs. If the feature is enabled, it will give a notice to run fsck to correct the on-disk layout. Enhancements: - reduce memory consumption for SMR drive - better discard handling for multiple partitions - tracepoints for f2fs_file_write_iter/f2fs_filemap_fault - allow to change CP_CHKSUM_OFFSET - detect wrong layout of large_nat_bitmap feature - enhance checking valid data indices Bug fixes: - Multiple partition support for SMR drive - deadlock problem in f2fs_balance_fs_bg - add boundary checks to fix abnormal behaviors on fuzzed images - inline_xattr space calculations - replace f2fs_bug_on with errors In addition, this series contains various memory boundary check and sanity check of on-disk consistency" * tag 'f2fs-for-v5.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (40 commits) f2fs: fix to avoid accessing xattr across the boundary f2fs: fix to avoid potential race on sbi->unusable_block_count access/update f2fs: add tracepoint for f2fs_filemap_fault() f2fs: introduce DATA_GENERIC_ENHANCE f2fs: fix to handle error in f2fs_disable_checkpoint() f2fs: remove redundant check in f2fs_file_write_iter() f2fs: fix to be aware of readonly device in write_checkpoint() f2fs: fix to skip recovery on readonly device f2fs: fix to consider multiple device for readonly check f2fs: relocate chksum_offset for large_nat_bitmap feature f2fs: allow unfixed f2fs_checkpoint.checksum_offset f2fs: Replace spaces with tab f2fs: insert space before the open parenthesis '(' f2fs: allow address pointer number of dnode aligning to specified size f2fs: introduce f2fs_read_single_page() for cleanup f2fs: mark is_extension_exist() inline f2fs: fix to set FI_UPDATE_WRITE correctly f2fs: fix to avoid panic in f2fs_inplace_write_data() f2fs: fix to do sanity check on valid block count of segment f2fs: fix to do sanity check on valid node/block count ...

Linus Torvalds committed 7 years ago

Commit 0d285442 parents fa4bff1 2777e6518 files · +688 −302Browse files

Unified · Split

18 files
  1. fs/f2fs/acl.c +2 −2
  2. fs/f2fs/checkpoint.c +86 −22
  3. fs/f2fs/data.c +165 −120
  4. fs/f2fs/f2fs.h +94 −33
  5. fs/f2fs/file.c +47 −29
  6. fs/f2fs/gc.c +13 −3
  7. fs/f2fs/inline.c +17 −0
  8. fs/f2fs/inode.c +7 −5
  9. fs/f2fs/namei.c +1 −1
  10. fs/f2fs/node.c +30 −13
  11. fs/f2fs/recovery.c +32 −5
  12. fs/f2fs/segment.c +38 −33
  13. fs/f2fs/segment.h +8 −8
  14. fs/f2fs/super.c +54 −16
  15. fs/f2fs/xattr.c +27 −9
  16. fs/f2fs/xattr.h +2 −0
  17. include/linux/f2fs_fs.h +8 −3
  18. include/trace/events/f2fs.h +57 −0
fs/f2fs/acl.c+2−2
@@ -285,7 +285,7 @@ static int f2fs_acl_create_masq(struct posix_acl *acl, umode_t *mode_p) · 284 unmodified lines
285285 /* assert(atomic_read(acl->a_refcount) == 1); */
286286
287287 FOREACH_ACL_ENTRY(pa, acl, pe) {
288− switch(pa->e_tag) {
288+ switch (pa->e_tag) {
289289 case ACL_USER_OBJ:
290290 pa->e_perm &= (mode >> 6) | ~S_IRWXO;
291291 mode &= (pa->e_perm << 6) | ~S_IRWXU;
@@ -326,7 +326,7 @@ static int f2fs_acl_create_masq(struct posix_acl *acl, umode_t *mode_p) · 34 unmodified lines
326326 }
327327
328328 *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
329− return not_equiv;
329+ return not_equiv;
330330 }
331331
332332 static int f2fs_acl_create(struct inode *dir, umode_t *mode,
fs/f2fs/checkpoint.c+86−22
@@ -66,7 +66,7 @@ static struct page *__get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index, · 65 unmodified lines
6666 .old_blkaddr = index,
6767 .new_blkaddr = index,
6868 .encrypted_page = NULL,
69− .is_meta = is_meta,
69+ .is_por = !is_meta,
7070 };
7171 int err;
7272
@@ -130,6 +130,30 @@ struct page *f2fs_get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index) · 57 unmodified lines
130130 return __get_meta_page(sbi, index, false);
131131 }
132132
133+static bool __is_bitmap_valid(struct f2fs_sb_info *sbi, block_t blkaddr,
134+ int type)
135+{
136+ struct seg_entry *se;
137+ unsigned int segno, offset;
138+ bool exist;
139+
140+ if (type != DATA_GENERIC_ENHANCE && type != DATA_GENERIC_ENHANCE_READ)
141+ return true;
142+
143+ segno = GET_SEGNO(sbi, blkaddr);
144+ offset = GET_BLKOFF_FROM_SEG0(sbi, blkaddr);
145+ se = get_seg_entry(sbi, segno);
146+
147+ exist = f2fs_test_bit(offset, se->cur_valid_map);
148+ if (!exist && type == DATA_GENERIC_ENHANCE) {
149+ f2fs_msg(sbi->sb, KERN_ERR, "Inconsistent error "
150+ "blkaddr:%u, sit bitmap:%d", blkaddr, exist);
151+ set_sbi_flag(sbi, SBI_NEED_FSCK);
152+ WARN_ON(1);
153+ }
154+ return exist;
155+}
156+
133157 bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
134158 block_t blkaddr, int type)
135159 {
@@ -151,15 +175,22 @@ bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, · 15 unmodified lines
151175 return false;
152176 break;
153177 case META_POR:
178+ if (unlikely(blkaddr >= MAX_BLKADDR(sbi) ||
179+ blkaddr < MAIN_BLKADDR(sbi)))
180+ return false;
181+ break;
154182 case DATA_GENERIC:
183+ case DATA_GENERIC_ENHANCE:
184+ case DATA_GENERIC_ENHANCE_READ:
155185 if (unlikely(blkaddr >= MAX_BLKADDR(sbi) ||
156− blkaddr < MAIN_BLKADDR(sbi))) {
157− if (type == DATA_GENERIC) {
158− f2fs_msg(sbi->sb, KERN_WARNING,
159− "access invalid blkaddr:%u", blkaddr);
160− WARN_ON(1);
161− }
186+ blkaddr < MAIN_BLKADDR(sbi))) {
187+ f2fs_msg(sbi->sb, KERN_WARNING,
188+ "access invalid blkaddr:%u", blkaddr);
189+ set_sbi_flag(sbi, SBI_NEED_FSCK);
190+ WARN_ON(1);
162191 return false;
192+ } else {
193+ return __is_bitmap_valid(sbi, blkaddr, type);
163194 }
164195 break;
165196 case META_GENERIC:
@@ -189,7 +220,7 @@ int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, · 23 unmodified lines
189220 .op_flags = sync ? (REQ_META | REQ_PRIO) : REQ_RAHEAD,
190221 .encrypted_page = NULL,
191222 .in_list = false,
192− .is_meta = (type != META_POR),
223+ .is_por = (type == META_POR),
193224 };
194225 struct blk_plug plug;
195226
@@ -644,6 +675,12 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi) · 448 unmodified lines
644675 if (!is_set_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG))
645676 return 0;
646677
678+ if (bdev_read_only(sbi->sb->s_bdev)) {
679+ f2fs_msg(sbi->sb, KERN_INFO, "write access "
680+ "unavailable, skipping orphan cleanup");
681+ return 0;
682+ }
683+
647684 if (s_flags & SB_RDONLY) {
648685 f2fs_msg(sbi->sb, KERN_INFO, "orphan cleanup on readonly fs");
649686 sbi->sb->s_flags &= ~SB_RDONLY;
@@ -758,13 +795,27 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk) · 108 unmodified lines
758795 }
759796 }
760797
798+static __u32 f2fs_checkpoint_chksum(struct f2fs_sb_info *sbi,
799+ struct f2fs_checkpoint *ckpt)
800+{
801+ unsigned int chksum_ofs = le32_to_cpu(ckpt->checksum_offset);
802+ __u32 chksum;
803+
804+ chksum = f2fs_crc32(sbi, ckpt, chksum_ofs);
805+ if (chksum_ofs < CP_CHKSUM_OFFSET) {
806+ chksum_ofs += sizeof(chksum);
807+ chksum = f2fs_chksum(sbi, chksum, (__u8 *)ckpt + chksum_ofs,
808+ F2FS_BLKSIZE - chksum_ofs);
809+ }
810+ return chksum;
811+}
812+
761813 static int get_checkpoint_version(struct f2fs_sb_info *sbi, block_t cp_addr,
762814 struct f2fs_checkpoint **cp_block, struct page **cp_page,
763815 unsigned long long *version)
764816 {
765− unsigned long blk_size = sbi->blocksize;
766817 size_t crc_offset = 0;
767− __u32 crc = 0;
818+ __u32 crc;
768819
769820 *cp_page = f2fs_get_meta_page(sbi, cp_addr);
770821 if (IS_ERR(*cp_page))
@@ -773,15 +824,27 @@ static int get_checkpoint_version(struct f2fs_sb_info *sbi, block_t cp_addr, · 2 unmodified lines
773824 *cp_block = (struct f2fs_checkpoint *)page_address(*cp_page);
774825
775826 crc_offset = le32_to_cpu((*cp_block)->checksum_offset);
776− if (crc_offset > (blk_size - sizeof(__le32))) {
827+ if (crc_offset < CP_MIN_CHKSUM_OFFSET ||
828+ crc_offset > CP_CHKSUM_OFFSET) {
777829 f2fs_put_page(*cp_page, 1);
778830 f2fs_msg(sbi->sb, KERN_WARNING,
779831 "invalid crc_offset: %zu", crc_offset);
780832 return -EINVAL;
781833 }
782834
783− crc = cur_cp_crc(*cp_block);
784− if (!f2fs_crc_valid(sbi, crc, *cp_block, crc_offset)) {
835+ if (__is_set_ckpt_flags(*cp_block, CP_LARGE_NAT_BITMAP_FLAG)) {
836+ if (crc_offset != CP_MIN_CHKSUM_OFFSET) {
837+ f2fs_put_page(*cp_page, 1);
838+ f2fs_msg(sbi->sb, KERN_WARNING,
839+ "layout of large_nat_bitmap is deprecated, "
840+ "run fsck to repair, chksum_offset: %zu",
841+ crc_offset);
842+ return -EINVAL;
843+ }
844+ }
845+
846+ crc = f2fs_checkpoint_chksum(sbi, *cp_block);
847+ if (crc != cur_cp_crc(*cp_block)) {
785848 f2fs_put_page(*cp_page, 1);
786849 f2fs_msg(sbi->sb, KERN_WARNING, "invalid crc value");
787850 return -EINVAL;
@@ -1009,13 +1072,11 @@ retry: · 221 unmodified lines
10091072 if (inode) {
10101073 unsigned long cur_ino = inode->i_ino;
10111074
1012− if (is_dir)
1013− F2FS_I(inode)->cp_task = current;
1075+ F2FS_I(inode)->cp_task = current;
10141076
10151077 filemap_fdatawrite(inode->i_mapping);
10161078
1017− if (is_dir)
1018− F2FS_I(inode)->cp_task = NULL;
1079+ F2FS_I(inode)->cp_task = NULL;
10191080
10201081 iput(inode);
10211082 /* We need to give cpu to another writers. */
@@ -1391,7 +1452,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) · 369 unmodified lines
13911452 get_sit_bitmap(sbi, __bitmap_ptr(sbi, SIT_BITMAP));
13921453 get_nat_bitmap(sbi, __bitmap_ptr(sbi, NAT_BITMAP));
13931454
1394− crc32 = f2fs_crc32(sbi, ckpt, le32_to_cpu(ckpt->checksum_offset));
1455+ crc32 = f2fs_checkpoint_chksum(sbi, ckpt);
13951456 *((__le32 *)((unsigned char *)ckpt +
13961457 le32_to_cpu(ckpt->checksum_offset)))
13971458 = cpu_to_le32(crc32);
@@ -1475,7 +1536,11 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) · 77 unmodified lines
14751536 clear_sbi_flag(sbi, SBI_IS_DIRTY);
14761537 clear_sbi_flag(sbi, SBI_NEED_CP);
14771538 clear_sbi_flag(sbi, SBI_QUOTA_SKIP_FLUSH);
1539+
1540+ spin_lock(&sbi->stat_lock);
14781541 sbi->unusable_block_count = 0;
1542+ spin_unlock(&sbi->stat_lock);
1543+
14791544 __set_cp_next_pack(sbi);
14801545
14811546 /*
@@ -1500,6 +1565,9 @@ int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) · 18 unmodified lines
15001565 unsigned long long ckpt_ver;
15011566 int err = 0;
15021567
1568+ if (f2fs_readonly(sbi->sb) || f2fs_hw_is_readonly(sbi))
1569+ return -EROFS;
1570+
15031571 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
15041572 if (cpc->reason != CP_PAUSE)
15051573 return 0;
@@ -1516,10 +1584,6 @@ int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) · 10 unmodified lines
15161584 err = -EIO;
15171585 goto out;
15181586 }
1519− if (f2fs_readonly(sbi->sb)) {
1520− err = -EROFS;
1521− goto out;
1522− }
15231587
15241588 trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "start block_ops");
15251589
fs/f2fs/data.c+165−120
@@ -218,12 +218,14 @@ struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, · 217 unmodified lines
218218 struct block_device *bdev = sbi->sb->s_bdev;
219219 int i;
220220
221− for (i = 0; i < sbi->s_ndevs; i++) {
222− if (FDEV(i).start_blk <= blk_addr &&
223− FDEV(i).end_blk >= blk_addr) {
224− blk_addr -= FDEV(i).start_blk;
225− bdev = FDEV(i).bdev;
226− break;
221+ if (f2fs_is_multi_device(sbi)) {
222+ for (i = 0; i < sbi->s_ndevs; i++) {
223+ if (FDEV(i).start_blk <= blk_addr &&
224+ FDEV(i).end_blk >= blk_addr) {
225+ blk_addr -= FDEV(i).start_blk;
226+ bdev = FDEV(i).bdev;
227+ break;
228+ }
227229 }
228230 }
229231 if (bio) {
@@ -237,6 +239,9 @@ int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr) · 7 unmodified lines
237239 {
238240 int i;
239241
242+ if (!f2fs_is_multi_device(sbi))
243+ return 0;
244+
240245 for (i = 0; i < sbi->s_ndevs; i++)
241246 if (FDEV(i).start_blk <= blkaddr && FDEV(i).end_blk >= blkaddr)
242247 return i;
@@ -420,7 +425,7 @@ static void __submit_merged_write_cond(struct f2fs_sb_info *sbi, · 177 unmodified lines
420425
421426 void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type)
422427 {
423− __submit_merged_write_cond(sbi, NULL, 0, 0, type, true);
428+ __submit_merged_write_cond(sbi, NULL, NULL, 0, type, true);
424429 }
425430
426431 void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi,
@@ -448,7 +453,8 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio) · 21 unmodified lines
448453 fio->encrypted_page : fio->page;
449454
450455 if (!f2fs_is_valid_blkaddr(fio->sbi, fio->new_blkaddr,
451− __is_meta_io(fio) ? META_GENERIC : DATA_GENERIC))
456+ fio->is_por ? META_POR : (__is_meta_io(fio) ?
457+ META_GENERIC : DATA_GENERIC_ENHANCE)))
452458 return -EFAULT;
453459
454460 trace_f2fs_submit_page_bio(page, fio);
@@ -498,9 +504,7 @@ next: · 43 unmodified lines
498504 spin_unlock(&io->io_lock);
499505 }
500506
501− if (__is_valid_data_blkaddr(fio->old_blkaddr))
502− verify_block_addr(fio, fio->old_blkaddr);
503− verify_block_addr(fio, fio->new_blkaddr);
507+ verify_fio_blkaddr(fio);
504508
505509 bio_page = fio->encrypted_page ? fio->encrypted_page : fio->page;
506510
@@ -557,9 +561,6 @@ static struct bio *f2fs_grab_read_bio(struct inode *inode, block_t blkaddr, · 50 unmodified lines
557561 struct bio_post_read_ctx *ctx;
558562 unsigned int post_read_steps = 0;
559563
560− if (!f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC))
561− return ERR_PTR(-EFAULT);
562−
563564 bio = f2fs_bio_alloc(sbi, min_t(int, nr_pages, BIO_MAX_PAGES), false);
564565 if (!bio)
565566 return ERR_PTR(-ENOMEM);
@@ -587,8 +588,10 @@ static struct bio *f2fs_grab_read_bio(struct inode *inode, block_t blkaddr, · 21 unmodified lines
587588 static int f2fs_submit_page_read(struct inode *inode, struct page *page,
588589 block_t blkaddr)
589590 {
590− struct bio *bio = f2fs_grab_read_bio(inode, blkaddr, 1, 0);
591+ struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
592+ struct bio *bio;
591593
594+ bio = f2fs_grab_read_bio(inode, blkaddr, 1, 0);
592595 if (IS_ERR(bio))
593596 return PTR_ERR(bio);
594597
@@ -600,8 +603,8 @@ static int f2fs_submit_page_read(struct inode *inode, struct page *page, · 5 unmodified lines
600603 return -EFAULT;
601604 }
602605 ClearPageError(page);
603− inc_page_count(F2FS_I_SB(inode), F2FS_RD_DATA);
604− __submit_bio(F2FS_I_SB(inode), bio, DATA);
606+ inc_page_count(sbi, F2FS_RD_DATA);
607+ __submit_bio(sbi, bio, DATA);
605608 return 0;
606609 }
607610
@@ -729,6 +732,11 @@ struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index, · 121 unmodified lines
729732
730733 if (f2fs_lookup_extent_cache(inode, index, &ei)) {
731734 dn.data_blkaddr = ei.blk + index - ei.fofs;
735+ if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), dn.data_blkaddr,
736+ DATA_GENERIC_ENHANCE_READ)) {
737+ err = -EFAULT;
738+ goto put_err;
739+ }
732740 goto got_it;
733741 }
734742
@@ -742,6 +750,13 @@ struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index, · 7 unmodified lines
742750 err = -ENOENT;
743751 goto put_err;
744752 }
753+ if (dn.data_blkaddr != NEW_ADDR &&
754+ !f2fs_is_valid_blkaddr(F2FS_I_SB(inode),
755+ dn.data_blkaddr,
756+ DATA_GENERIC_ENHANCE)) {
757+ err = -EFAULT;
758+ goto put_err;
759+ }
745760 got_it:
746761 if (PageUptodate(page)) {
747762 unlock_page(page);
@@ -1084,12 +1099,12 @@ next_block: · 336 unmodified lines
10841099 blkaddr = datablock_addr(dn.inode, dn.node_page, dn.ofs_in_node);
10851100
10861101 if (__is_valid_data_blkaddr(blkaddr) &&
1087− !f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC)) {
1102+ !f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC_ENHANCE)) {
10881103 err = -EFAULT;
10891104 goto sync_out;
10901105 }
10911106
1092− if (is_valid_data_blkaddr(sbi, blkaddr)) {
1107+ if (__is_valid_data_blkaddr(blkaddr)) {
10931108 /* use out-place-update for driect IO under LFS mode */
10941109 if (test_opt(sbi, LFS) && flag == F2FS_GET_BLOCK_DIO &&
10951110 map->m_may_create) {
@@ -1499,6 +1514,118 @@ out: · 403 unmodified lines
14991514 return ret;
15001515 }
15011516
1517+static int f2fs_read_single_page(struct inode *inode, struct page *page,
1518+ unsigned nr_pages,
1519+ struct f2fs_map_blocks *map,
1520+ struct bio **bio_ret,
1521+ sector_t *last_block_in_bio,
1522+ bool is_readahead)
1523+{
1524+ struct bio *bio = *bio_ret;
1525+ const unsigned blkbits = inode->i_blkbits;
1526+ const unsigned blocksize = 1 << blkbits;
1527+ sector_t block_in_file;
1528+ sector_t last_block;
1529+ sector_t last_block_in_file;
1530+ sector_t block_nr;
1531+ int ret = 0;
1532+
1533+ block_in_file = (sector_t)page->index;
1534+ last_block = block_in_file + nr_pages;
1535+ last_block_in_file = (i_size_read(inode) + blocksize - 1) >>
1536+ blkbits;
1537+ if (last_block > last_block_in_file)
1538+ last_block = last_block_in_file;
1539+
1540+ /* just zeroing out page which is beyond EOF */
1541+ if (block_in_file >= last_block)
1542+ goto zero_out;
1543+ /*
1544+ * Map blocks using the previous result first.
1545+ */
1546+ if ((map->m_flags & F2FS_MAP_MAPPED) &&
1547+ block_in_file > map->m_lblk &&
1548+ block_in_file < (map->m_lblk + map->m_len))
1549+ goto got_it;
1550+
1551+ /*
1552+ * Then do more f2fs_map_blocks() calls until we are
1553+ * done with this page.
1554+ */
1555+ map->m_lblk = block_in_file;
1556+ map->m_len = last_block - block_in_file;
1557+
1558+ ret = f2fs_map_blocks(inode, map, 0, F2FS_GET_BLOCK_DEFAULT);
1559+ if (ret)
1560+ goto out;
1561+got_it:
1562+ if ((map->m_flags & F2FS_MAP_MAPPED)) {
1563+ block_nr = map->m_pblk + block_in_file - map->m_lblk;
1564+ SetPageMappedToDisk(page);
1565+
1566+ if (!PageUptodate(page) && !cleancache_get_page(page)) {
1567+ SetPageUptodate(page);
1568+ goto confused;
1569+ }
1570+
1571+ if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), block_nr,
1572+ DATA_GENERIC_ENHANCE_READ)) {
1573+ ret = -EFAULT;
1574+ goto out;
1575+ }
1576+ } else {
1577+zero_out:
1578+ zero_user_segment(page, 0, PAGE_SIZE);
1579+ if (!PageUptodate(page))
1580+ SetPageUptodate(page);
1581+ unlock_page(page);
1582+ goto out;
1583+ }
1584+
1585+ /*
1586+ * This page will go to BIO. Do we need to send this
1587+ * BIO off first?
1588+ */
1589+ if (bio && (*last_block_in_bio != block_nr - 1 ||
1590+ !__same_bdev(F2FS_I_SB(inode), block_nr, bio))) {
1591+submit_and_realloc:
1592+ __submit_bio(F2FS_I_SB(inode), bio, DATA);
1593+ bio = NULL;
1594+ }
1595+ if (bio == NULL) {
1596+ bio = f2fs_grab_read_bio(inode, block_nr, nr_pages,
1597+ is_readahead ? REQ_RAHEAD : 0);
1598+ if (IS_ERR(bio)) {
1599+ ret = PTR_ERR(bio);
1600+ bio = NULL;
1601+ goto out;
1602+ }
1603+ }
1604+
1605+ /*
1606+ * If the page is under writeback, we need to wait for
1607+ * its completion to see the correct decrypted data.
1608+ */
1609+ f2fs_wait_on_block_writeback(inode, block_nr);
1610+
1611+ if (bio_add_page(bio, page, blocksize, 0) < blocksize)
1612+ goto submit_and_realloc;
1613+
1614+ inc_page_count(F2FS_I_SB(inode), F2FS_RD_DATA);
1615+ ClearPageError(page);
1616+ *last_block_in_bio = block_nr;
1617+ goto out;
1618+confused:
1619+ if (bio) {
1620+ __submit_bio(F2FS_I_SB(inode), bio, DATA);
1621+ bio = NULL;
1622+ }
1623+ unlock_page(page);
1624+out:
1625+ *bio_ret = bio;
1626+ return ret;
1627+}
1628+
15021629 /*
15031630 * This function was originally taken from fs/mpage.c, and customized for f2fs.
15041631 * Major change was from block_size == page_size in f2fs by default.
@@ -1515,13 +1642,8 @@ static int f2fs_mpage_readpages(struct address_space *mapping, · 10 unmodified lines
15151642 struct bio *bio = NULL;
15161643 sector_t last_block_in_bio = 0;
15171644 struct inode *inode = mapping->host;
1518− const unsigned blkbits = inode->i_blkbits;
1519− const unsigned blocksize = 1 << blkbits;
1520− sector_t block_in_file;
1521− sector_t last_block;
1522− sector_t last_block_in_file;
1523− sector_t block_nr;
15241645 struct f2fs_map_blocks map;
1646+ int ret = 0;
15251647
15261648 map.m_pblk = 0;
15271649 map.m_lblk = 0;
@@ -1544,98 +1666,13 @@ static int f2fs_mpage_readpages(struct address_space *mapping, · 16 unmodified lines
15441666 goto next_page;
15451667 }
15461668
1547− block_in_file = (sector_t)page->index;
1548− last_block = block_in_file + nr_pages;
1549− last_block_in_file = (i_size_read(inode) + blocksize - 1) >>
1550− blkbits;
1551− if (last_block > last_block_in_file)
1552− last_block = last_block_in_file;
1553−
1554− /* just zeroing out page which is beyond EOF */
1555− if (block_in_file >= last_block)
1556− goto zero_out;
1557− /*
1558− * Map blocks using the previous result first.
1559− */
1560− if ((map.m_flags & F2FS_MAP_MAPPED) &&
1561− block_in_file > map.m_lblk &&
1562− block_in_file < (map.m_lblk + map.m_len))
1563− goto got_it;
1564−
1565− /*
1566− * Then do more f2fs_map_blocks() calls until we are
1567− * done with this page.
1568− */
1569− map.m_lblk = block_in_file;
1570− map.m_len = last_block - block_in_file;
1571−
1572− if (f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_DEFAULT))
1573− goto set_error_page;
1574−got_it:
1575− if ((map.m_flags & F2FS_MAP_MAPPED)) {
1576− block_nr = map.m_pblk + block_in_file - map.m_lblk;
1577− SetPageMappedToDisk(page);
1578−
1579− if (!PageUptodate(page) && !cleancache_get_page(page)) {
1580− SetPageUptodate(page);
1581− goto confused;
1582− }
1583−
1584− if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), block_nr,
1585− DATA_GENERIC))
1586− goto set_error_page;
1587− } else {
1588−zero_out:
1669+ ret = f2fs_read_single_page(inode, page, nr_pages, &map, &bio,
1670+ &last_block_in_bio, is_readahead);
1671+ if (ret) {
1672+ SetPageError(page);
15891673 zero_user_segment(page, 0, PAGE_SIZE);
1590− if (!PageUptodate(page))
1591− SetPageUptodate(page);
15921674 unlock_page(page);
1593− goto next_page;
15941675 }
1595−
1596− /*
1597− * This page will go to BIO. Do we need to send this
1598− * BIO off first?
1599− */
1600− if (bio && (last_block_in_bio != block_nr - 1 ||
1601− !__same_bdev(F2FS_I_SB(inode), block_nr, bio))) {
1602−submit_and_realloc:
1603− __submit_bio(F2FS_I_SB(inode), bio, DATA);
1604− bio = NULL;
1605− }
1606− if (bio == NULL) {
1607− bio = f2fs_grab_read_bio(inode, block_nr, nr_pages,
1608− is_readahead ? REQ_RAHEAD : 0);
1609− if (IS_ERR(bio)) {
1610− bio = NULL;
1611− goto set_error_page;
1612− }
1613− }
1614−
1615− /*
1616− * If the page is under writeback, we need to wait for
1617− * its completion to see the correct decrypted data.
1618− */
1619− f2fs_wait_on_block_writeback(inode, block_nr);
1620−
1621− if (bio_add_page(bio, page, blocksize, 0) < blocksize)
1622− goto submit_and_realloc;
1623−
1624− inc_page_count(F2FS_I_SB(inode), F2FS_RD_DATA);
1625− ClearPageError(page);
1626− last_block_in_bio = block_nr;
1627− goto next_page;
1628−set_error_page:
1629− SetPageError(page);
1630− zero_user_segment(page, 0, PAGE_SIZE);
1631− unlock_page(page);
1632− goto next_page;
1633−confused:
1634− if (bio) {
1635− __submit_bio(F2FS_I_SB(inode), bio, DATA);
1636− bio = NULL;
1637− }
1638− unlock_page(page);
16391676 next_page:
16401677 if (pages)
16411678 put_page(page);
@@ -1643,7 +1680,7 @@ next_page: · 1 unmodified line
16431680 BUG_ON(pages && !list_empty(pages));
16441681 if (bio)
16451682 __submit_bio(F2FS_I_SB(inode), bio, DATA);
1646− return 0;
1683+ return pages ? 0 : ret;
16471684 }
16481685
16491686 static int f2fs_read_data_page(struct file *file, struct page *page)
@@ -1813,7 +1850,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio) · 163 unmodified lines
18131850 fio->old_blkaddr = ei.blk + page->index - ei.fofs;
18141851
18151852 if (!f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr,
1816− DATA_GENERIC))
1853+ DATA_GENERIC_ENHANCE))
18171854 return -EFAULT;
18181855
18191856 ipu_force = true;
@@ -1840,7 +1877,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio) · 20 unmodified lines
18401877 got_it:
18411878 if (__is_valid_data_blkaddr(fio->old_blkaddr) &&
18421879 !f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr,
1843− DATA_GENERIC)) {
1880+ DATA_GENERIC_ENHANCE)) {
18441881 err = -EFAULT;
18451882 goto out_writepage;
18461883 }
@@ -1848,7 +1885,8 @@ got_it: · 1 unmodified line
18481885 * If current allocation needs SSR,
18491886 * it had better in-place writes for updated data.
18501887 */
1851− if (ipu_force || (is_valid_data_blkaddr(fio->sbi, fio->old_blkaddr) &&
1888+ if (ipu_force ||
1889+ (__is_valid_data_blkaddr(fio->old_blkaddr) &&
18521890 need_inplace_update(fio))) {
18531891 err = encrypt_one_page(fio);
18541892 if (err)
@@ -1866,9 +1904,10 @@ got_it: · 11 unmodified lines
18661904 true);
18671905 if (PageWriteback(page))
18681906 end_page_writeback(page);
1907+ } else {
1908+ set_inode_flag(inode, FI_UPDATE_WRITE);
18691909 }
18701910 trace_f2fs_do_write_data_page(fio->page, IPU);
1871− set_inode_flag(inode, FI_UPDATE_WRITE);
18721911 return err;
18731912 }
18741913
@@ -2030,7 +2069,8 @@ out: · 155 unmodified lines
20302069 }
20312070
20322071 unlock_page(page);
2033− if (!S_ISDIR(inode->i_mode) && !IS_NOQUOTA(inode))
2072+ if (!S_ISDIR(inode->i_mode) && !IS_NOQUOTA(inode) &&
2073+ !F2FS_I(inode)->cp_task)
20342074 f2fs_balance_fs(sbi, need_balance_fs);
20352075
20362076 if (unlikely(f2fs_cp_error(sbi))) {
@@ -2491,6 +2531,11 @@ repeat: · 454 unmodified lines
24912531 zero_user_segment(page, 0, PAGE_SIZE);
24922532 SetPageUptodate(page);
24932533 } else {
2534+ if (!f2fs_is_valid_blkaddr(sbi, blkaddr,
2535+ DATA_GENERIC_ENHANCE_READ)) {
2536+ err = -EFAULT;
2537+ goto fail;
2538+ }
24942539 err = f2fs_submit_page_read(inode, page, blkaddr);
24952540 if (err)
24962541 goto fail;
fs/f2fs/f2fs.h+94−33
@@ -210,7 +210,14 @@ enum { · 209 unmodified lines
210210 META_SSA,
211211 META_MAX,
212212 META_POR,
213− DATA_GENERIC,
213+ DATA_GENERIC, /* check range only */
214+ DATA_GENERIC_ENHANCE, /* strong check on range and segment bitmap */
215+ DATA_GENERIC_ENHANCE_READ, /*
216+ * strong check on range and segment
217+ * bitmap but no warning due to race
218+ * condition of read on truncated area
219+ * by extent_cache
220+ */
214221 META_GENERIC,
215222 };
216223
@@ -1041,7 +1048,7 @@ struct f2fs_io_info { · 824 unmodified lines
10411048 bool submitted; /* indicate IO submission */
10421049 int need_lock; /* indicate we need to lock cp_rwsem */
10431050 bool in_list; /* indicate fio is in io_list */
1044− bool is_meta; /* indicate borrow meta inode mapping or not */
1051+ bool is_por; /* indicate IO is from recovery or not */
10451052 bool retry; /* need to reallocate block address */
10461053 enum iostat_type io_type; /* io type */
10471054 struct writeback_control *io_wbc; /* writeback control */
@@ -1068,8 +1075,8 @@ struct f2fs_dev_info { · 20 unmodified lines
10681075 block_t start_blk;
10691076 block_t end_blk;
10701077 #ifdef CONFIG_BLK_DEV_ZONED
1071− unsigned int nr_blkz; /* Total number of zones */
1072− u8 *blkz_type; /* Array of zones type */
1078+ unsigned int nr_blkz; /* Total number of zones */
1079+ unsigned long *blkz_seq; /* Bitmap indicating sequential zones */
10731080 #endif
10741081 };
10751082
@@ -1366,6 +1373,17 @@ static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) · 290 unmodified lines
13661373 }
13671374 #endif
13681375
1376+/*
1377+ * Test if the mounted volume is a multi-device volume.
1378+ * - For a single regular disk volume, sbi->s_ndevs is 0.
1379+ * - For a single zoned disk volume, sbi->s_ndevs is 1.
1380+ * - For a multi-device volume, sbi->s_ndevs is always 2 or more.
1381+ */
1382+static inline bool f2fs_is_multi_device(struct f2fs_sb_info *sbi)
1383+{
1384+ return sbi->s_ndevs > 1;
1385+}
1386+
13691387 /* For write statistics. Suppose sector size is 512 bytes,
13701388 * and the return value is in kbytes. s is of struct f2fs_sb_info.
13711389 */
@@ -1777,6 +1795,7 @@ enospc: · 405 unmodified lines
17771795 return -ENOSPC;
17781796 }
17791797
1798+void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...);
17801799 static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
17811800 struct inode *inode,
17821801 block_t count)
@@ -1785,13 +1804,21 @@ static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, · 2 unmodified lines
17851804
17861805 spin_lock(&sbi->stat_lock);
17871806 f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
1788− f2fs_bug_on(sbi, inode->i_blocks < sectors);
17891807 sbi->total_valid_block_count -= (block_t)count;
17901808 if (sbi->reserved_blocks &&
17911809 sbi->current_reserved_blocks < sbi->reserved_blocks)
17921810 sbi->current_reserved_blocks = min(sbi->reserved_blocks,
17931811 sbi->current_reserved_blocks + count);
17941812 spin_unlock(&sbi->stat_lock);
1813+ if (unlikely(inode->i_blocks < sectors)) {
1814+ f2fs_msg(sbi->sb, KERN_WARNING,
1815+ "Inconsistent i_blocks, ino:%lu, iblocks:%llu, sectors:%llu",
1816+ inode->i_ino,
1817+ (unsigned long long)inode->i_blocks,
1818+ (unsigned long long)sectors);
1819+ set_sbi_flag(sbi, SBI_NEED_FSCK);
1820+ return;
1821+ }
17951822 f2fs_i_blocks_write(inode, count, false, true);
17961823 }
17971824
@@ -1889,7 +1916,11 @@ static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) · 91 unmodified lines
18891916 if (is_set_ckpt_flags(sbi, CP_LARGE_NAT_BITMAP_FLAG)) {
18901917 offset = (flag == SIT_BITMAP) ?
18911918 le32_to_cpu(ckpt->nat_ver_bitmap_bytesize) : 0;
1892− return &ckpt->sit_nat_version_bitmap + offset;
1919+ /*
1920+ * if large_nat_bitmap feature is enabled, leave checksum
1921+ * protection for all nat/sit bitmaps.
1922+ */
1923+ return &ckpt->sit_nat_version_bitmap + offset + sizeof(__le32);
18931924 }
18941925
18951926 if (__cp_payload(sbi) > 0) {
@@ -2008,7 +2039,6 @@ static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, · 112 unmodified lines
20082039
20092040 f2fs_bug_on(sbi, !sbi->total_valid_block_count);
20102041 f2fs_bug_on(sbi, !sbi->total_valid_node_count);
2011− f2fs_bug_on(sbi, !is_inode && !inode->i_blocks);
20122042
20132043 sbi->total_valid_node_count--;
20142044 sbi->total_valid_block_count--;
@@ -2018,10 +2048,19 @@ static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, · 3 unmodified lines
20182048
20192049 spin_unlock(&sbi->stat_lock);
20202050
2021− if (is_inode)
2051+ if (is_inode) {
20222052 dquot_free_inode(inode);
2023− else
2053+ } else {
2054+ if (unlikely(inode->i_blocks == 0)) {
2055+ f2fs_msg(sbi->sb, KERN_WARNING,
2056+ "Inconsistent i_blocks, ino:%lu, iblocks:%llu",
2057+ inode->i_ino,
2058+ (unsigned long long)inode->i_blocks);
2059+ set_sbi_flag(sbi, SBI_NEED_FSCK);
2060+ return;
2061+ }
20242062 f2fs_i_blocks_write(inode, 1, false, true);
2063+ }
20252064 }
20262065
20272066 static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
@@ -2545,7 +2584,14 @@ static inline int f2fs_has_inline_xattr(struct inode *inode) · 517 unmodified lines
25452584
25462585 static inline unsigned int addrs_per_inode(struct inode *inode)
25472586 {
2548− return CUR_ADDRS_PER_INODE(inode) - get_inline_xattr_addrs(inode);
2587+ unsigned int addrs = CUR_ADDRS_PER_INODE(inode) -
2588+ get_inline_xattr_addrs(inode);
2589+ return ALIGN_DOWN(addrs, 1);
2590+}
2591+
2592+static inline unsigned int addrs_per_block(struct inode *inode)
2593+{
2594+ return ALIGN_DOWN(DEF_ADDRS_PER_BLOCK, 1);
25492595 }
25502596
25512597 static inline void *inline_xattr_addr(struct inode *inode, struct page *page)
@@ -2558,7 +2604,9 @@ static inline void *inline_xattr_addr(struct inode *inode, struct page *page) · 6 unmodified lines
25582604
25592605 static inline int inline_xattr_size(struct inode *inode)
25602606 {
2561− return get_inline_xattr_addrs(inode) * sizeof(__le32);
2607+ if (f2fs_has_inline_xattr(inode))
2608+ return get_inline_xattr_addrs(inode) * sizeof(__le32);
2609+ return 0;
25622610 }
25632611
25642612 static inline int f2fs_has_inline_data(struct inode *inode)
@@ -2800,12 +2848,10 @@ static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, · 235 unmodified lines
28002848
28012849 #define __is_large_section(sbi) ((sbi)->segs_per_sec > 1)
28022850
2803−#define __is_meta_io(fio) (PAGE_TYPE_OF_BIO((fio)->type) == META && \
2804− (!is_read_io((fio)->op) || (fio)->is_meta))
2851+#define __is_meta_io(fio) (PAGE_TYPE_OF_BIO((fio)->type) == META)
28052852
28062853 bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
28072854 block_t blkaddr, int type);
2808−void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...);
28092855 static inline void verify_blkaddr(struct f2fs_sb_info *sbi,
28102856 block_t blkaddr, int type)
28112857 {
@@ -2824,15 +2870,6 @@ static inline bool __is_valid_data_blkaddr(block_t blkaddr) · 12 unmodified lines
28242870 return true;
28252871 }
28262872
2827−static inline bool is_valid_data_blkaddr(struct f2fs_sb_info *sbi,
2828− block_t blkaddr)
2829−{
2830− if (!__is_valid_data_blkaddr(blkaddr))
2831− return false;
2832− verify_blkaddr(sbi, blkaddr, DATA_GENERIC);
2833− return true;
2834−}
2835−
28362873 static inline void f2fs_set_page_private(struct page *page,
28372874 unsigned long data)
28382875 {
@@ -3530,16 +3567,12 @@ F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND); · 691 unmodified lines
35303567 F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM);
35313568
35323569 #ifdef CONFIG_BLK_DEV_ZONED
3533−static inline int get_blkz_type(struct f2fs_sb_info *sbi,
3534− struct block_device *bdev, block_t blkaddr)
3570+static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi,
3571+ block_t blkaddr)
35353572 {
35363573 unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz;
3537− int i;
35383574
3539− for (i = 0; i < sbi->s_ndevs; i++)
3540− if (FDEV(i).bdev == bdev)
3541− return FDEV(i).blkz_type[zno];
3542− return -EINVAL;
3575+ return test_bit(zno, FDEV(devi).blkz_seq);
35433576 }
35443577 #endif
35453578
@@ -3548,9 +3581,23 @@ static inline bool f2fs_hw_should_discard(struct f2fs_sb_info *sbi) · 2 unmodified lines
35483581 return f2fs_sb_has_blkzoned(sbi);
35493582 }
35503583
3584+static inline bool f2fs_bdev_support_discard(struct block_device *bdev)
3585+{
3586+ return blk_queue_discard(bdev_get_queue(bdev)) ||
3587+ bdev_is_zoned(bdev);
3588+}
3589+
35513590 static inline bool f2fs_hw_support_discard(struct f2fs_sb_info *sbi)
35523591 {
3553− return blk_queue_discard(bdev_get_queue(sbi->sb->s_bdev));
3592+ int i;
3593+
3594+ if (!f2fs_is_multi_device(sbi))
3595+ return f2fs_bdev_support_discard(sbi->sb->s_bdev);
3596+
3597+ for (i = 0; i < sbi->s_ndevs; i++)
3598+ if (f2fs_bdev_support_discard(FDEV(i).bdev))
3599+ return true;
3600+ return false;
35543601 }
35553602
35563603 static inline bool f2fs_realtime_discard_enable(struct f2fs_sb_info *sbi)
@@ -3559,6 +3606,20 @@ static inline bool f2fs_realtime_discard_enable(struct f2fs_sb_info *sbi) · 2 unmodified lines
35593606 f2fs_hw_should_discard(sbi);
35603607 }
35613608
3609+static inline bool f2fs_hw_is_readonly(struct f2fs_sb_info *sbi)
3610+{
3611+ int i;
3612+
3613+ if (!f2fs_is_multi_device(sbi))
3614+ return bdev_read_only(sbi->sb->s_bdev);
3615+
3616+ for (i = 0; i < sbi->s_ndevs; i++)
3617+ if (bdev_read_only(FDEV(i).bdev))
3618+ return true;
3619+ return false;
3620+}
3621+
3622+
35623623 static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt)
35633624 {
35643625 clear_opt(sbi, ADAPTIVE);
@@ -3614,7 +3675,7 @@ static inline bool f2fs_force_buffered_io(struct inode *inode, · 49 unmodified lines
36143675
36153676 if (f2fs_post_read_required(inode))
36163677 return true;
3617− if (sbi->s_ndevs)
3678+ if (f2fs_is_multi_device(sbi))
36183679 return true;
36193680 /*
36203681 * for blkzoned device, fallback direct IO to buffered IO, so
@@ -3651,4 +3712,4 @@ static inline bool is_journalled_quota(struct f2fs_sb_info *sbi) · 30 unmodified lines
36513712 return false;
36523713 }
36533714
3654−#endif
3715+#endif /* _LINUX_F2FS_H */
fs/f2fs/file.c+47−29
@@ -39,6 +39,8 @@ static vm_fault_t f2fs_filemap_fault(struct vm_fault *vmf) · 38 unmodified lines
3939 ret = filemap_fault(vmf);
4040 up_read(&F2FS_I(inode)->i_mmap_sem);
4141
42+ trace_f2fs_filemap_fault(inode, vmf->pgoff, (unsigned long)ret);
43+
4244 return ret;
4345 }
4446
@@ -356,7 +358,7 @@ static bool __found_offset(struct f2fs_sb_info *sbi, block_t blkaddr, · 311 unmodified lines
356358 switch (whence) {
357359 case SEEK_DATA:
358360 if ((blkaddr == NEW_ADDR && dirty == pgofs) ||
359− is_valid_data_blkaddr(sbi, blkaddr))
361+ __is_valid_data_blkaddr(blkaddr))
360362 return true;
361363 break;
362364 case SEEK_HOLE:
@@ -422,7 +424,7 @@ static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence) · 59 unmodified lines
422424
423425 if (__is_valid_data_blkaddr(blkaddr) &&
424426 !f2fs_is_valid_blkaddr(F2FS_I_SB(inode),
425− blkaddr, DATA_GENERIC)) {
427+ blkaddr, DATA_GENERIC_ENHANCE)) {
426428 f2fs_put_dnode(&dn);
427429 goto fail;
428430 }
@@ -523,7 +525,8 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count) · 94 unmodified lines
523525 f2fs_set_data_blkaddr(dn);
524526
525527 if (__is_valid_data_blkaddr(blkaddr) &&
526− !f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC))
528+ !f2fs_is_valid_blkaddr(sbi, blkaddr,
529+ DATA_GENERIC_ENHANCE))
527530 continue;
528531
529532 f2fs_invalidate_blocks(sbi, blkaddr);
@@ -552,7 +555,7 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count) · 22 unmodified lines
552555
553556 void f2fs_truncate_data_blocks(struct dnode_of_data *dn)
554557 {
555− f2fs_truncate_data_blocks_range(dn, ADDRS_PER_BLOCK);
558+ f2fs_truncate_data_blocks_range(dn, ADDRS_PER_BLOCK(dn->inode));
556559 }
557560
558561 static int truncate_partial_data_page(struct inode *inode, u64 from,
@@ -1006,7 +1009,8 @@ next_dnode: · 447 unmodified lines
10061009 } else if (ret == -ENOENT) {
10071010 if (dn.max_level == 0)
10081011 return -ENOENT;
1009− done = min((pgoff_t)ADDRS_PER_BLOCK - dn.ofs_in_node, len);
1012+ done = min((pgoff_t)ADDRS_PER_BLOCK(inode) - dn.ofs_in_node,
1013+ len);
10101014 blkaddr += done;
10111015 do_replace += done;
10121016 goto next;
@@ -1017,6 +1021,14 @@ next_dnode: · 4 unmodified lines
10171021 for (i = 0; i < done; i++, blkaddr++, do_replace++, dn.ofs_in_node++) {
10181022 *blkaddr = datablock_addr(dn.inode,
10191023 dn.node_page, dn.ofs_in_node);
1024+
1025+ if (__is_valid_data_blkaddr(*blkaddr) &&
1026+ !f2fs_is_valid_blkaddr(sbi, *blkaddr,
1027+ DATA_GENERIC_ENHANCE)) {
1028+ f2fs_put_dnode(&dn);
1029+ return -EFAULT;
1030+ }
1031+
10201032 if (!f2fs_is_checkpointed_data(sbi, *blkaddr)) {
10211033
10221034 if (test_opt(sbi, LFS)) {
@@ -1157,7 +1169,7 @@ static int __exchange_data_block(struct inode *src_inode, · 134 unmodified lines
11571169 int ret;
11581170
11591171 while (len) {
1160− olen = min((pgoff_t)4 * ADDRS_PER_BLOCK, len);
1172+ olen = min((pgoff_t)4 * ADDRS_PER_BLOCK(src_inode), len);
11611173
11621174 src_blkaddr = f2fs_kvzalloc(F2FS_I_SB(src_inode),
11631175 array_size(olen, sizeof(block_t)),
@@ -2573,10 +2585,10 @@ static int f2fs_ioc_flush_device(struct file *filp, unsigned long arg) · 1409 unmodified lines
25732585 sizeof(range)))
25742586 return -EFAULT;
25752587
2576− if (sbi->s_ndevs <= 1 || sbi->s_ndevs - 1 <= range.dev_num ||
2588+ if (!f2fs_is_multi_device(sbi) || sbi->s_ndevs - 1 <= range.dev_num ||
25772589 __is_large_section(sbi)) {
25782590 f2fs_msg(sbi->sb, KERN_WARNING,
2579− "Can't flush %u in %d for segs_per_sec %u != 1\n",
2591+ "Can't flush %u in %d for segs_per_sec %u != 1",
25802592 range.dev_num, sbi->s_ndevs,
25812593 sbi->segs_per_sec);
25822594 return -EINVAL;
@@ -2858,7 +2870,7 @@ int f2fs_pin_file_control(struct inode *inode, bool inc) · 275 unmodified lines
28582870
28592871 if (fi->i_gc_failures[GC_FAILURE_PIN] > sbi->gc_pin_file_threshold) {
28602872 f2fs_msg(sbi->sb, KERN_WARNING,
2861− "%s: Enable GC = ino %lx after %x GC trials\n",
2873+ "%s: Enable GC = ino %lx after %x GC trials",
28622874 __func__, inode->i_ino,
28632875 fi->i_gc_failures[GC_FAILURE_PIN]);
28642876 clear_inode_flag(inode, FI_PIN_FILE);
@@ -3035,15 +3047,21 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) · 170 unmodified lines
30353047 struct inode *inode = file_inode(file);
30363048 ssize_t ret;
30373049
3038− if (unlikely(f2fs_cp_error(F2FS_I_SB(inode))))
3039− return -EIO;
3050+ if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) {
3051+ ret = -EIO;
3052+ goto out;
3053+ }
30403054
3041− if ((iocb->ki_flags & IOCB_NOWAIT) && !(iocb->ki_flags & IOCB_DIRECT))
3042− return -EINVAL;
3055+ if ((iocb->ki_flags & IOCB_NOWAIT) && !(iocb->ki_flags & IOCB_DIRECT)) {
3056+ ret = -EINVAL;
3057+ goto out;
3058+ }
30433059
30443060 if (!inode_trylock(inode)) {
3045− if (iocb->ki_flags & IOCB_NOWAIT)
3046− return -EAGAIN;
3061+ if (iocb->ki_flags & IOCB_NOWAIT) {
3062+ ret = -EAGAIN;
3063+ goto out;
3064+ }
30473065 inode_lock(inode);
30483066 }
30493067
@@ -3056,19 +3074,16 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) · 6 unmodified lines
30563074 if (iov_iter_fault_in_readable(from, iov_iter_count(from)))
30573075 set_inode_flag(inode, FI_NO_PREALLOC);
30583076
3059− if ((iocb->ki_flags & IOCB_NOWAIT) &&
3060− (iocb->ki_flags & IOCB_DIRECT)) {
3061− if (!f2fs_overwrite_io(inode, iocb->ki_pos,
3077+ if ((iocb->ki_flags & IOCB_NOWAIT)) {
3078+ if (!f2fs_overwrite_io(inode, iocb->ki_pos,
30623079 iov_iter_count(from)) ||
3063− f2fs_has_inline_data(inode) ||
3064− f2fs_force_buffered_io(inode,
3065− iocb, from)) {
3066− clear_inode_flag(inode,
3067− FI_NO_PREALLOC);
3068− inode_unlock(inode);
3069− return -EAGAIN;
3070− }
3071−
3080+ f2fs_has_inline_data(inode) ||
3081+ f2fs_force_buffered_io(inode, iocb, from)) {
3082+ clear_inode_flag(inode, FI_NO_PREALLOC);
3083+ inode_unlock(inode);
3084+ ret = -EAGAIN;
3085+ goto out;
3086+ }
30723087 } else {
30733088 preallocated = true;
30743089 target_size = iocb->ki_pos + iov_iter_count(from);
@@ -3077,7 +3092,8 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) · 2 unmodified lines
30773092 if (err) {
30783093 clear_inode_flag(inode, FI_NO_PREALLOC);
30793094 inode_unlock(inode);
3080− return err;
3095+ ret = err;
3096+ goto out;
30813097 }
30823098 }
30833099 ret = __generic_file_write_iter(iocb, from);
@@ -3091,7 +3107,9 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) · 7 unmodified lines
30913107 f2fs_update_iostat(F2FS_I_SB(inode), APP_WRITE_IO, ret);
30923108 }
30933109 inode_unlock(inode);
3094−
3110+out:
3111+ trace_f2fs_file_write_iter(inode, iocb->ki_pos,
3112+ iov_iter_count(from), ret);
30953113 if (ret > 0)
30963114 ret = generic_write_sync(iocb, ret);
30973115 return ret;
fs/f2fs/gc.c+13−3
@@ -591,7 +591,7 @@ block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode) · 590 unmodified lines
591591 int dec = (node_ofs - indirect_blks - 3) / (NIDS_PER_BLOCK + 1);
592592 bidx = node_ofs - 5 - dec;
593593 }
594− return bidx * ADDRS_PER_BLOCK + ADDRS_PER_INODE(inode);
594+ return bidx * ADDRS_PER_BLOCK(inode) + ADDRS_PER_INODE(inode);
595595 }
596596
597597 static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
@@ -656,6 +656,11 @@ static int ra_data_block(struct inode *inode, pgoff_t index) · 58 unmodified lines
656656
657657 if (f2fs_lookup_extent_cache(inode, index, &ei)) {
658658 dn.data_blkaddr = ei.blk + index - ei.fofs;
659+ if (unlikely(!f2fs_is_valid_blkaddr(sbi, dn.data_blkaddr,
660+ DATA_GENERIC_ENHANCE_READ))) {
661+ err = -EFAULT;
662+ goto put_page;
663+ }
659664 goto got_it;
660665 }
661666
@@ -665,8 +670,12 @@ static int ra_data_block(struct inode *inode, pgoff_t index) · 3 unmodified lines
665670 goto put_page;
666671 f2fs_put_dnode(&dn);
667672
673+ if (!__is_valid_data_blkaddr(dn.data_blkaddr)) {
674+ err = -ENOENT;
675+ goto put_page;
676+ }
668677 if (unlikely(!f2fs_is_valid_blkaddr(sbi, dn.data_blkaddr,
669− DATA_GENERIC))) {
678+ DATA_GENERIC_ENHANCE))) {
670679 err = -EFAULT;
671680 goto put_page;
672681 }
@@ -1175,6 +1184,7 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi, · 502 unmodified lines
11751184 "type [%d, %d] in SSA and SIT",
11761185 segno, type, GET_SUM_TYPE((&sum->footer)));
11771186 set_sbi_flag(sbi, SBI_NEED_FSCK);
1187+ f2fs_stop_checkpoint(sbi, false);
11781188 goto skip;
11791189 }
11801190
@@ -1346,7 +1356,7 @@ void f2fs_build_gc_manager(struct f2fs_sb_info *sbi) · 165 unmodified lines
13461356 sbi->gc_pin_file_threshold = DEF_GC_FAILED_PINNED_FILES;
13471357
13481358 /* give warm/cold data area from slower device */
1349− if (sbi->s_ndevs && !__is_large_section(sbi))
1359+ if (f2fs_is_multi_device(sbi) && !__is_large_section(sbi))
13501360 SIT_I(sbi)->last_victim[ALLOC_NEXT] =
13511361 GET_SEGNO(sbi, FDEV(0).end_blk) + 1;
13521362 }
fs/f2fs/inline.c+17−0
@@ -420,6 +420,14 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct page *ipage, · 419 unmodified lines
420420 stat_dec_inline_dir(dir);
421421 clear_inode_flag(dir, FI_INLINE_DENTRY);
422422
423+ /*
424+ * should retrieve reserved space which was used to keep
425+ * inline_dentry's structure for backward compatibility.
426+ */
427+ if (!f2fs_sb_has_flexible_inline_xattr(F2FS_I_SB(dir)) &&
428+ !f2fs_has_inline_xattr(dir))
429+ F2FS_I(dir)->i_inline_xattr_size = 0;
430+
423431 f2fs_i_depth_write(dir, 1);
424432 if (i_size_read(dir) < PAGE_SIZE)
425433 f2fs_i_size_write(dir, PAGE_SIZE);
@@ -501,6 +509,15 @@ static int f2fs_move_rehashed_dirents(struct inode *dir, struct page *ipage, · 75 unmodified lines
501509
502510 stat_dec_inline_dir(dir);
503511 clear_inode_flag(dir, FI_INLINE_DENTRY);
512+
513+ /*
514+ * should retrieve reserved space which was used to keep
515+ * inline_dentry's structure for backward compatibility.
516+ */
517+ if (!f2fs_sb_has_flexible_inline_xattr(F2FS_I_SB(dir)) &&
518+ !f2fs_has_inline_xattr(dir))
519+ F2FS_I(dir)->i_inline_xattr_size = 0;
520+
504521 kvfree(backup_dentry);
505522 return 0;
506523 recover:
fs/f2fs/inode.c+7−5
@@ -73,7 +73,7 @@ static int __written_first_block(struct f2fs_sb_info *sbi, · 72 unmodified lines
7373
7474 if (!__is_valid_data_blkaddr(addr))
7575 return 1;
76− if (!f2fs_is_valid_blkaddr(sbi, addr, DATA_GENERIC))
76+ if (!f2fs_is_valid_blkaddr(sbi, addr, DATA_GENERIC_ENHANCE))
7777 return -EFAULT;
7878 return 0;
7979 }
@@ -177,8 +177,8 @@ bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page) · 97 unmodified lines
177177
178178 if (provided != calculated)
179179 f2fs_msg(sbi->sb, KERN_WARNING,
180− "checksum invalid, ino = %x, %x vs. %x",
181− ino_of_node(page), provided, calculated);
180+ "checksum invalid, nid = %lu, ino_of_node = %x, %x vs. %x",
181+ page->index, ino_of_node(page), provided, calculated);
182182
183183 return provided == calculated;
184184 }
@@ -267,9 +267,10 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page) · 82 unmodified lines
267267 struct extent_info *ei = &F2FS_I(inode)->extent_tree->largest;
268268
269269 if (ei->len &&
270− (!f2fs_is_valid_blkaddr(sbi, ei->blk, DATA_GENERIC) ||
270+ (!f2fs_is_valid_blkaddr(sbi, ei->blk,
271+ DATA_GENERIC_ENHANCE) ||
271272 !f2fs_is_valid_blkaddr(sbi, ei->blk + ei->len - 1,
272− DATA_GENERIC))) {
273+ DATA_GENERIC_ENHANCE))) {
273274 set_sbi_flag(sbi, SBI_NEED_FSCK);
274275 f2fs_msg(sbi->sb, KERN_WARNING,
275276 "%s: inode (ino=%lx) extent info [%u, %u, %u] "
@@ -488,6 +489,7 @@ make_now: · 212 unmodified lines
488489 return inode;
489490
490491 bad_inode:
492+ f2fs_inode_synced(inode);
491493 iget_failed(inode);
492494 trace_f2fs_iget_exit(inode, ret);
493495 return ERR_PTR(ret);
fs/f2fs/namei.c+1−1
@@ -143,7 +143,7 @@ fail_drop: · 142 unmodified lines
143143 return ERR_PTR(err);
144144 }
145145
146−static int is_extension_exist(const unsigned char *s, const char *sub)
146+static inline int is_extension_exist(const unsigned char *s, const char *sub)
147147 {
148148 size_t slen = strlen(s);
149149 size_t sublen = strlen(sub);
fs/f2fs/node.c+30−13
@@ -454,7 +454,7 @@ static void set_node_addr(struct f2fs_sb_info *sbi, struct node_info *ni, · 453 unmodified lines
454454 new_blkaddr == NULL_ADDR);
455455 f2fs_bug_on(sbi, nat_get_blkaddr(e) == NEW_ADDR &&
456456 new_blkaddr == NEW_ADDR);
457− f2fs_bug_on(sbi, is_valid_data_blkaddr(sbi, nat_get_blkaddr(e)) &&
457+ f2fs_bug_on(sbi, __is_valid_data_blkaddr(nat_get_blkaddr(e)) &&
458458 new_blkaddr == NEW_ADDR);
459459
460460 /* increment version no as node is removed */
@@ -465,7 +465,7 @@ static void set_node_addr(struct f2fs_sb_info *sbi, struct node_info *ni, · 4 unmodified lines
465465
466466 /* change address */
467467 nat_set_blkaddr(e, new_blkaddr);
468− if (!is_valid_data_blkaddr(sbi, new_blkaddr))
468+ if (!__is_valid_data_blkaddr(new_blkaddr))
469469 set_nat_flag(e, IS_CHECKPOINTED, false);
470470 __set_nat_cache_dirty(nm_i, e);
471471
@@ -526,6 +526,7 @@ int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid, · 54 unmodified lines
526526 struct f2fs_nat_entry ne;
527527 struct nat_entry *e;
528528 pgoff_t index;
529+ block_t blkaddr;
529530 int i;
530531
531532 ni->nid = nid;
@@ -569,6 +570,11 @@ int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid, · 37 unmodified lines
569570 node_info_from_raw_nat(ni, &ne);
570571 f2fs_put_page(page, 1);
571572 cache:
573+ blkaddr = le32_to_cpu(ne.block_addr);
574+ if (__is_valid_data_blkaddr(blkaddr) &&
575+ !f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC_ENHANCE))
576+ return -EFAULT;
577+
572578 /* cache nat entry */
573579 cache_nat_entry(sbi, nid, &ne);
574580 return 0;
@@ -600,9 +606,9 @@ static void f2fs_ra_node_pages(struct page *parent, int start, int n) · 25 unmodified lines
600606 pgoff_t f2fs_get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs)
601607 {
602608 const long direct_index = ADDRS_PER_INODE(dn->inode);
603− const long direct_blks = ADDRS_PER_BLOCK;
604− const long indirect_blks = ADDRS_PER_BLOCK * NIDS_PER_BLOCK;
605− unsigned int skipped_unit = ADDRS_PER_BLOCK;
609+ const long direct_blks = ADDRS_PER_BLOCK(dn->inode);
610+ const long indirect_blks = ADDRS_PER_BLOCK(dn->inode) * NIDS_PER_BLOCK;
611+ unsigned int skipped_unit = ADDRS_PER_BLOCK(dn->inode);
606612 int cur_level = dn->cur_level;
607613 int max_level = dn->max_level;
608614 pgoff_t base = 0;
@@ -638,9 +644,9 @@ static int get_node_path(struct inode *inode, long block, · 29 unmodified lines
638644 int offset[4], unsigned int noffset[4])
639645 {
640646 const long direct_index = ADDRS_PER_INODE(inode);
641− const long direct_blks = ADDRS_PER_BLOCK;
647+ const long direct_blks = ADDRS_PER_BLOCK(inode);
642648 const long dptrs_per_blk = NIDS_PER_BLOCK;
643− const long indirect_blks = ADDRS_PER_BLOCK * NIDS_PER_BLOCK;
649+ const long indirect_blks = ADDRS_PER_BLOCK(inode) * NIDS_PER_BLOCK;
644650 const long dindirect_blks = indirect_blks * NIDS_PER_BLOCK;
645651 int n = 0;
646652 int level = 0;
@@ -1181,8 +1187,14 @@ int f2fs_remove_inode_page(struct inode *inode) · 534 unmodified lines
11811187 f2fs_put_dnode(&dn);
11821188 return -EIO;
11831189 }
1184− f2fs_bug_on(F2FS_I_SB(inode),
1185− inode->i_blocks != 0 && inode->i_blocks != 8);
1190+
1191+ if (unlikely(inode->i_blocks != 0 && inode->i_blocks != 8)) {
1192+ f2fs_msg(F2FS_I_SB(inode)->sb, KERN_WARNING,
1193+ "Inconsistent i_blocks, ino:%lu, iblocks:%llu",
1194+ inode->i_ino,
1195+ (unsigned long long)inode->i_blocks);
1196+ set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_FSCK);
1197+ }
11861198
11871199 /* will put inode & node pages */
11881200 err = truncate_node(&dn);
@@ -1277,9 +1289,10 @@ static int read_node_page(struct page *page, int op_flags) · 88 unmodified lines
12771289 int err;
12781290
12791291 if (PageUptodate(page)) {
1280−#ifdef CONFIG_F2FS_CHECK_FS
1281− f2fs_bug_on(sbi, !f2fs_inode_chksum_verify(sbi, page));
1282−#endif
1292+ if (!f2fs_inode_chksum_verify(sbi, page)) {
1293+ ClearPageUptodate(page);
1294+ return -EBADMSG;
1295+ }
12831296 return LOCKED_PAGE;
12841297 }
12851298
@@ -1543,7 +1556,8 @@ static int __write_node_page(struct page *page, bool atomic, bool *submitted, · 257 unmodified lines
15431556 }
15441557
15451558 if (__is_valid_data_blkaddr(ni.blk_addr) &&
1546− !f2fs_is_valid_blkaddr(sbi, ni.blk_addr, DATA_GENERIC)) {
1559+ !f2fs_is_valid_blkaddr(sbi, ni.blk_addr,
1560+ DATA_GENERIC_ENHANCE)) {
15471561 up_read(&sbi->node_write);
15481562 goto redirty_out;
15491563 }
@@ -2078,6 +2092,9 @@ static bool add_free_nid(struct f2fs_sb_info *sbi, · 528 unmodified lines
20782092 if (unlikely(nid == 0))
20792093 return false;
20802094
2095+ if (unlikely(f2fs_check_nid_range(sbi, nid)))
2096+ return false;
2097+
20812098 i = f2fs_kmem_cache_alloc(free_nid_slab, GFP_NOFS);
20822099 i->nid = nid;
20832100 i->state = FREE_NID;
fs/f2fs/recovery.c+32−5
@@ -325,8 +325,10 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head, · 324 unmodified lines
325325 break;
326326 }
327327
328− if (!is_recoverable_dnode(page))
328+ if (!is_recoverable_dnode(page)) {
329+ f2fs_put_page(page, 1);
329330 break;
331+ }
330332
331333 if (!is_fsync_dnode(page))
332334 goto next;
@@ -338,8 +340,10 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head, · 5 unmodified lines
338340 if (!check_only &&
339341 IS_INODE(page) && is_dent_dnode(page)) {
340342 err = f2fs_recover_inode_page(sbi, page);
341− if (err)
343+ if (err) {
344+ f2fs_put_page(page, 1);
342345 break;
346+ }
343347 quota_inode = true;
344348 }
345349
@@ -355,6 +359,7 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head, · 9 unmodified lines
355359 err = 0;
356360 goto next;
357361 }
362+ f2fs_put_page(page, 1);
358363 break;
359364 }
360365 }
@@ -370,6 +375,7 @@ next: · 9 unmodified lines
370375 "%s: detect looped node chain, "
371376 "blkaddr:%u, next:%u",
372377 __func__, blkaddr, next_blkaddr_of_node(page));
378+ f2fs_put_page(page, 1);
373379 err = -EINVAL;
374380 break;
375381 }
@@ -380,7 +386,6 @@ next: · 4 unmodified lines
380386
381387 f2fs_ra_meta_pages_cond(sbi, blkaddr);
382388 }
383− f2fs_put_page(page, 1);
384389 return err;
385390 }
386391
@@ -546,7 +551,15 @@ retry_dn: · 159 unmodified lines
546551 goto err;
547552
548553 f2fs_bug_on(sbi, ni.ino != ino_of_node(page));
549− f2fs_bug_on(sbi, ofs_of_node(dn.node_page) != ofs_of_node(page));
554+
555+ if (ofs_of_node(dn.node_page) != ofs_of_node(page)) {
556+ f2fs_msg(sbi->sb, KERN_WARNING,
557+ "Inconsistent ofs_of_node, ino:%lu, ofs:%u, %u",
558+ inode->i_ino, ofs_of_node(dn.node_page),
559+ ofs_of_node(page));
560+ err = -EFAULT;
561+ goto err;
562+ }
550563
551564 for (; start < end; start++, dn.ofs_in_node++) {
552565 block_t src, dest;
@@ -554,6 +567,18 @@ retry_dn: · 1 unmodified line
554567 src = datablock_addr(dn.inode, dn.node_page, dn.ofs_in_node);
555568 dest = datablock_addr(dn.inode, page, dn.ofs_in_node);
556569
570+ if (__is_valid_data_blkaddr(src) &&
571+ !f2fs_is_valid_blkaddr(sbi, src, META_POR)) {
572+ err = -EFAULT;
573+ goto err;
574+ }
575+
576+ if (__is_valid_data_blkaddr(dest) &&
577+ !f2fs_is_valid_blkaddr(sbi, dest, META_POR)) {
578+ err = -EFAULT;
579+ goto err;
580+ }
581+
557582 /* skip recovering if dest is the same as src */
558583 if (src == dest)
559584 continue;
@@ -666,8 +691,10 @@ static int recover_data(struct f2fs_sb_info *sbi, struct list_head *inode_list, · 106 unmodified lines
666691 */
667692 if (IS_INODE(page)) {
668693 err = recover_inode(entry->inode, page);
669− if (err)
694+ if (err) {
695+ f2fs_put_page(page, 1);
670696 break;
697+ }
671698 }
672699 if (entry->last_dentry == blkaddr) {
673700 err = recover_dentry(entry->inode, page, dir_list);
fs/f2fs/segment.c+38−33
@@ -580,7 +580,7 @@ static int submit_flush_wait(struct f2fs_sb_info *sbi, nid_t ino) · 579 unmodified lines
580580 int ret = 0;
581581 int i;
582582
583− if (!sbi->s_ndevs)
583+ if (!f2fs_is_multi_device(sbi))
584584 return __submit_flush_wait(sbi, sbi->sb->s_bdev);
585585
586586 for (i = 0; i < sbi->s_ndevs; i++) {
@@ -648,7 +648,8 @@ int f2fs_issue_flush(struct f2fs_sb_info *sbi, nid_t ino) · 61 unmodified lines
648648 return ret;
649649 }
650650
651− if (atomic_inc_return(&fcc->queued_flush) == 1 || sbi->s_ndevs > 1) {
651+ if (atomic_inc_return(&fcc->queued_flush) == 1 ||
652+ f2fs_is_multi_device(sbi)) {
652653 ret = submit_flush_wait(sbi, ino);
653654 atomic_dec(&fcc->queued_flush);
654655
@@ -754,7 +755,7 @@ int f2fs_flush_device_cache(struct f2fs_sb_info *sbi) · 99 unmodified lines
754755 {
755756 int ret = 0, i;
756757
757− if (!sbi->s_ndevs)
758+ if (!f2fs_is_multi_device(sbi))
758759 return 0;
759760
760761 for (i = 1; i < sbi->s_ndevs; i++) {
@@ -1367,9 +1368,12 @@ static int __queue_discard_cmd(struct f2fs_sb_info *sbi, · 606 unmodified lines
13671368 {
13681369 block_t lblkstart = blkstart;
13691370
1371+ if (!f2fs_bdev_support_discard(bdev))
1372+ return 0;
1373+
13701374 trace_f2fs_queue_discard(bdev, blkstart, blklen);
13711375
1372− if (sbi->s_ndevs) {
1376+ if (f2fs_is_multi_device(sbi)) {
13731377 int devi = f2fs_target_device_index(sbi, blkstart);
13741378
13751379 blkstart -= FDEV(devi).start_blk;
@@ -1732,42 +1736,36 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi, · 356 unmodified lines
17321736 block_t lblkstart = blkstart;
17331737 int devi = 0;
17341738
1735− if (sbi->s_ndevs) {
1739+ if (f2fs_is_multi_device(sbi)) {
17361740 devi = f2fs_target_device_index(sbi, blkstart);
1741+ if (blkstart < FDEV(devi).start_blk ||
1742+ blkstart > FDEV(devi).end_blk) {
1743+ f2fs_msg(sbi->sb, KERN_ERR, "Invalid block %x",
1744+ blkstart);
1745+ return -EIO;
1746+ }
17371747 blkstart -= FDEV(devi).start_blk;
17381748 }
17391749
1740− /*
1741− * We need to know the type of the zone: for conventional zones,
1742− * use regular discard if the drive supports it. For sequential
1743− * zones, reset the zone write pointer.
1744− */
1745− switch (get_blkz_type(sbi, bdev, blkstart)) {
1746−
1747− case BLK_ZONE_TYPE_CONVENTIONAL:
1748− if (!blk_queue_discard(bdev_get_queue(bdev)))
1749− return 0;
1750− return __queue_discard_cmd(sbi, bdev, lblkstart, blklen);
1751− case BLK_ZONE_TYPE_SEQWRITE_REQ:
1752− case BLK_ZONE_TYPE_SEQWRITE_PREF:
1750+ /* For sequential zones, reset the zone write pointer */
1751+ if (f2fs_blkz_is_seq(sbi, devi, blkstart)) {
17531752 sector = SECTOR_FROM_BLOCK(blkstart);
17541753 nr_sects = SECTOR_FROM_BLOCK(blklen);
17551754
17561755 if (sector & (bdev_zone_sectors(bdev) - 1) ||
17571756 nr_sects != bdev_zone_sectors(bdev)) {
1758− f2fs_msg(sbi->sb, KERN_INFO,
1759− "(%d) %s: Unaligned discard attempted (block %x + %x)",
1757+ f2fs_msg(sbi->sb, KERN_ERR,
1758+ "(%d) %s: Unaligned zone reset attempted (block %x + %x)",
17601759 devi, sbi->s_ndevs ? FDEV(devi).path: "",
17611760 blkstart, blklen);
17621761 return -EIO;
17631762 }
17641763 trace_f2fs_issue_reset_zone(bdev, blkstart);
1765− return blkdev_reset_zones(bdev, sector,
1766− nr_sects, GFP_NOFS);
1767− default:
1768− /* Unknown zone type: broken device ? */
1769− return -EIO;
1764+ return blkdev_reset_zones(bdev, sector, nr_sects, GFP_NOFS);
17701765 }
1766+
1767+ /* For conventional zones, use regular discard if supported */
1768+ return __queue_discard_cmd(sbi, bdev, lblkstart, blklen);
17711769 }
17721770 #endif
17731771
@@ -1775,8 +1773,7 @@ static int __issue_discard_async(struct f2fs_sb_info *sbi, · 1 unmodified line
17751773 struct block_device *bdev, block_t blkstart, block_t blklen)
17761774 {
17771775 #ifdef CONFIG_BLK_DEV_ZONED
1778− if (f2fs_sb_has_blkzoned(sbi) &&
1779− bdev_zoned_model(bdev) != BLK_ZONED_NONE)
1776+ if (f2fs_sb_has_blkzoned(sbi) && bdev_is_zoned(bdev))
17801777 return __f2fs_issue_discard_zone(sbi, bdev, blkstart, blklen);
17811778 #endif
17821779 return __queue_discard_cmd(sbi, bdev, blkstart, blklen);
@@ -2172,8 +2169,11 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del) · 389 unmodified lines
21722169 * before, we must track that to know how much space we
21732170 * really have.
21742171 */
2175− if (f2fs_test_bit(offset, se->ckpt_valid_map))
2172+ if (f2fs_test_bit(offset, se->ckpt_valid_map)) {
2173+ spin_lock(&sbi->stat_lock);
21762174 sbi->unusable_block_count++;
2175+ spin_unlock(&sbi->stat_lock);
2176+ }
21772177 }
21782178
21792179 if (f2fs_test_and_clear_bit(offset, se->discard_map))
@@ -2220,7 +2220,7 @@ bool f2fs_is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr) · 40 unmodified lines
22202220 struct seg_entry *se;
22212221 bool is_cp = false;
22222222
2223− if (!is_valid_data_blkaddr(sbi, blkaddr))
2223+ if (!__is_valid_data_blkaddr(blkaddr))
22242224 return true;
22252225
22262226 down_read(&sit_i->sentry_lock);
@@ -3089,7 +3089,7 @@ static void update_device_state(struct f2fs_io_info *fio) · 862 unmodified lines
30893089 struct f2fs_sb_info *sbi = fio->sbi;
30903090 unsigned int devidx;
30913091
3092− if (!sbi->s_ndevs)
3092+ if (!f2fs_is_multi_device(sbi))
30933093 return;
30943094
30953095 devidx = f2fs_target_device_index(sbi, fio->new_blkaddr);
@@ -3187,13 +3187,18 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio) · 91 unmodified lines
31873187 {
31883188 int err;
31893189 struct f2fs_sb_info *sbi = fio->sbi;
3190+ unsigned int segno;
31903191
31913192 fio->new_blkaddr = fio->old_blkaddr;
31923193 /* i/o temperature is needed for passing down write hints */
31933194 __get_segment_type(fio);
31943195
3195− f2fs_bug_on(sbi, !IS_DATASEG(get_seg_entry(sbi,
3196− GET_SEGNO(sbi, fio->new_blkaddr))->type));
3196+ segno = GET_SEGNO(sbi, fio->new_blkaddr);
3197+
3198+ if (!IS_DATASEG(get_seg_entry(sbi, segno)->type)) {
3199+ set_sbi_flag(sbi, SBI_NEED_FSCK);
3200+ return -EFAULT;
3201+ }
31973202
31983203 stat_inc_inplace_blocks(fio->sbi);
31993204
@@ -3336,7 +3341,7 @@ void f2fs_wait_on_block_writeback(struct inode *inode, block_t blkaddr) · 136 unmodified lines
33363341 if (!f2fs_post_read_required(inode))
33373342 return;
33383343
3339− if (!is_valid_data_blkaddr(sbi, blkaddr))
3344+ if (!__is_valid_data_blkaddr(blkaddr))
33403345 return;
33413346
33423347 cpage = find_lock_page(META_MAPPING(sbi), blkaddr);
fs/f2fs/segment.h+8−8
@@ -82,7 +82,7 @@ · 81 unmodified lines
8282 (GET_SEGOFF_FROM_SEG0(sbi, blk_addr) & ((sbi)->blocks_per_seg - 1))
8383
8484 #define GET_SEGNO(sbi, blk_addr) \
85− ((!is_valid_data_blkaddr(sbi, blk_addr)) ? \
85+ ((!__is_valid_data_blkaddr(blk_addr)) ? \
8686 NULL_SEGNO : GET_L2R_SEGNO(FREE_I(sbi), \
8787 GET_SEGNO_FROM_SEG0(sbi, blk_addr)))
8888 #define BLKS_PER_SEC(sbi) \
@@ -656,14 +656,15 @@ static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno) · 567 unmodified lines
656656 f2fs_bug_on(sbi, segno > TOTAL_SEGS(sbi) - 1);
657657 }
658658
659−static inline void verify_block_addr(struct f2fs_io_info *fio, block_t blk_addr)
659+static inline void verify_fio_blkaddr(struct f2fs_io_info *fio)
660660 {
661661 struct f2fs_sb_info *sbi = fio->sbi;
662662
663− if (__is_meta_io(fio))
664− verify_blkaddr(sbi, blk_addr, META_GENERIC);
665− else
666− verify_blkaddr(sbi, blk_addr, DATA_GENERIC);
663+ if (__is_valid_data_blkaddr(fio->old_blkaddr))
664+ verify_blkaddr(sbi, fio->old_blkaddr, __is_meta_io(fio) ?
665+ META_GENERIC : DATA_GENERIC);
666+ verify_blkaddr(sbi, fio->new_blkaddr, __is_meta_io(fio) ?
667+ META_GENERIC : DATA_GENERIC_ENHANCE);
667668 }
668669
669670 /*
@@ -672,7 +673,6 @@ static inline void verify_block_addr(struct f2fs_io_info *fio, block_t blk_addr) · 2 unmodified lines
672673 static inline int check_block_count(struct f2fs_sb_info *sbi,
673674 int segno, struct f2fs_sit_entry *raw_sit)
674675 {
675−#ifdef CONFIG_F2FS_CHECK_FS
676676 bool is_valid = test_bit_le(0, raw_sit->valid_map) ? true : false;
677677 int valid_blocks = 0;
678678 int cur_pos = 0, next_pos;
@@ -699,7 +699,7 @@ static inline int check_block_count(struct f2fs_sb_info *sbi, · 20 unmodified lines
699699 set_sbi_flag(sbi, SBI_NEED_FSCK);
700700 return -EINVAL;
701701 }
702−#endif
702+
703703 /* check segment usage, and check boundary of a given segment number */
704704 if (unlikely(GET_SIT_VBLOCKS(raw_sit) > sbi->blocks_per_seg
705705 || segno > TOTAL_SEGS(sbi) - 1)) {
fs/f2fs/super.c+54−16
@@ -1019,7 +1019,7 @@ static void destroy_device_list(struct f2fs_sb_info *sbi) · 1018 unmodified lines
10191019 for (i = 0; i < sbi->s_ndevs; i++) {
10201020 blkdev_put(FDEV(i).bdev, FMODE_EXCL);
10211021 #ifdef CONFIG_BLK_DEV_ZONED
1022− kvfree(FDEV(i).blkz_type);
1022+ kvfree(FDEV(i).blkz_seq);
10231023 #endif
10241024 }
10251025 kvfree(sbi->devs);
@@ -1221,10 +1221,13 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) · 195 unmodified lines
12211221 buf->f_blocks = total_count - start_count;
12221222 buf->f_bfree = user_block_count - valid_user_blocks(sbi) -
12231223 sbi->current_reserved_blocks;
1224+
1225+ spin_lock(&sbi->stat_lock);
12241226 if (unlikely(buf->f_bfree <= sbi->unusable_block_count))
12251227 buf->f_bfree = 0;
12261228 else
12271229 buf->f_bfree -= sbi->unusable_block_count;
1230+ spin_unlock(&sbi->stat_lock);
12281231
12291232 if (buf->f_bfree > F2FS_OPTION(sbi).root_reserved_blocks)
12301233 buf->f_bavail = buf->f_bfree -
@@ -1499,9 +1502,15 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi) · 268 unmodified lines
14991502 mutex_lock(&sbi->gc_mutex);
15001503 cpc.reason = CP_PAUSE;
15011504 set_sbi_flag(sbi, SBI_CP_DISABLED);
1502− f2fs_write_checkpoint(sbi, &cpc);
1505+ err = f2fs_write_checkpoint(sbi, &cpc);
1506+ if (err)
1507+ goto out_unlock;
15031508
1509+ spin_lock(&sbi->stat_lock);
15041510 sbi->unusable_block_count = 0;
1511+ spin_unlock(&sbi->stat_lock);
1512+
1513+out_unlock:
15051514 mutex_unlock(&sbi->gc_mutex);
15061515 restore_flag:
15071516 sbi->sb->s_flags = s_flags; /* Restore MS_RDONLY status */
@@ -2271,7 +2280,7 @@ static const struct export_operations f2fs_export_ops = { · 763 unmodified lines
22712280 static loff_t max_file_blocks(void)
22722281 {
22732282 loff_t result = 0;
2274− loff_t leaf_count = ADDRS_PER_BLOCK;
2283+ loff_t leaf_count = DEF_ADDRS_PER_BLOCK;
22752284
22762285 /*
22772286 * note: previously, result is equal to (DEF_ADDRS_PER_INODE -
@@ -2449,7 +2458,7 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi, · 171 unmodified lines
24492458 /* Currently, support only 4KB page cache size */
24502459 if (F2FS_BLKSIZE != PAGE_SIZE) {
24512460 f2fs_msg(sb, KERN_INFO,
2452− "Invalid page_cache_size (%lu), supports only 4KB\n",
2461+ "Invalid page_cache_size (%lu), supports only 4KB",
24532462 PAGE_SIZE);
24542463 return 1;
24552464 }
@@ -2458,7 +2467,7 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi, · 2 unmodified lines
24582467 blocksize = 1 << le32_to_cpu(raw_super->log_blocksize);
24592468 if (blocksize != F2FS_BLKSIZE) {
24602469 f2fs_msg(sb, KERN_INFO,
2461− "Invalid blocksize (%u), supports only 4KB\n",
2470+ "Invalid blocksize (%u), supports only 4KB",
24622471 blocksize);
24632472 return 1;
24642473 }
@@ -2466,7 +2475,7 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi, · 1 unmodified line
24662475 /* check log blocks per segment */
24672476 if (le32_to_cpu(raw_super->log_blocks_per_seg) != 9) {
24682477 f2fs_msg(sb, KERN_INFO,
2469− "Invalid log blocks per segment (%u)\n",
2478+ "Invalid log blocks per segment (%u)",
24702479 le32_to_cpu(raw_super->log_blocks_per_seg));
24712480 return 1;
24722481 }
@@ -2587,7 +2596,8 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) · 114 unmodified lines
25872596 unsigned int log_blocks_per_seg;
25882597 unsigned int segment_count_main;
25892598 unsigned int cp_pack_start_sum, cp_payload;
2590− block_t user_block_count;
2599+ block_t user_block_count, valid_user_blocks;
2600+ block_t avail_node_count, valid_node_count;
25912601 int i, j;
25922602
25932603 total = le32_to_cpu(raw_super->segment_count);
@@ -2622,6 +2632,24 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) · 28 unmodified lines
26222632 return 1;
26232633 }
26242634
2635+ valid_user_blocks = le64_to_cpu(ckpt->valid_block_count);
2636+ if (valid_user_blocks > user_block_count) {
2637+ f2fs_msg(sbi->sb, KERN_ERR,
2638+ "Wrong valid_user_blocks: %u, user_block_count: %u",
2639+ valid_user_blocks, user_block_count);
2640+ return 1;
2641+ }
2642+
2643+ valid_node_count = le32_to_cpu(ckpt->valid_node_count);
2644+ avail_node_count = sbi->total_node_count - sbi->nquota_files -
2645+ F2FS_RESERVED_NODE_NUM;
2646+ if (valid_node_count > avail_node_count) {
2647+ f2fs_msg(sbi->sb, KERN_ERR,
2648+ "Wrong valid_node_count: %u, avail_node_count: %u",
2649+ valid_node_count, avail_node_count);
2650+ return 1;
2651+ }
2652+
26252653 main_segs = le32_to_cpu(raw_super->segment_count_main);
26262654 blocks_per_seg = sbi->blocks_per_seg;
26272655
@@ -2793,9 +2821,11 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) · 165 unmodified lines
27932821 if (nr_sectors & (bdev_zone_sectors(bdev) - 1))
27942822 FDEV(devi).nr_blkz++;
27952823
2796− FDEV(devi).blkz_type = f2fs_kmalloc(sbi, FDEV(devi).nr_blkz,
2797− GFP_KERNEL);
2798− if (!FDEV(devi).blkz_type)
2824+ FDEV(devi).blkz_seq = f2fs_kzalloc(sbi,
2825+ BITS_TO_LONGS(FDEV(devi).nr_blkz)
2826+ * sizeof(unsigned long),
2827+ GFP_KERNEL);
2828+ if (!FDEV(devi).blkz_seq)
27992829 return -ENOMEM;
28002830
28012831 #define F2FS_REPORT_NR_ZONES 4096
@@ -2822,7 +2852,8 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) · 20 unmodified lines
28222852 }
28232853
28242854 for (i = 0; i < nr_zones; i++) {
2825− FDEV(devi).blkz_type[n] = zones[i].type;
2855+ if (zones[i].type != BLK_ZONE_TYPE_CONVENTIONAL)
2856+ set_bit(n, FDEV(devi).blkz_seq);
28262857 sector += zones[i].len;
28272858 n++;
28282859 }
@@ -3105,7 +3136,7 @@ try_onemore: · 276 unmodified lines
31053136 #ifndef CONFIG_BLK_DEV_ZONED
31063137 if (f2fs_sb_has_blkzoned(sbi)) {
31073138 f2fs_msg(sb, KERN_ERR,
3108− "Zoned block device support is not enabled\n");
3139+ "Zoned block device support is not enabled");
31093140 err = -EOPNOTSUPP;
31103141 goto free_sb_buf;
31113142 }
@@ -3350,10 +3381,17 @@ try_onemore: · 238 unmodified lines
33503381 * mount should be failed, when device has readonly mode, and
33513382 * previous checkpoint was not done by clean system shutdown.
33523383 */
3353− if (bdev_read_only(sb->s_bdev) &&
3354− !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
3355− err = -EROFS;
3356− goto free_meta;
3384+ if (f2fs_hw_is_readonly(sbi)) {
3385+ if (!is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
3386+ err = -EROFS;
3387+ f2fs_msg(sb, KERN_ERR,
3388+ "Need to recover fsync data, but "
3389+ "write access unavailable");
3390+ goto free_meta;
3391+ }
3392+ f2fs_msg(sbi->sb, KERN_INFO, "write access "
3393+ "unavailable, skipping recovery");
3394+ goto reset_checkpoint;
33573395 }
33583396
33593397 if (need_fsck)
fs/f2fs/xattr.c+27−9
@@ -202,12 +202,17 @@ static inline const struct xattr_handler *f2fs_xattr_handler(int index) · 201 unmodified lines
202202 return handler;
203203 }
204204
205−static struct f2fs_xattr_entry *__find_xattr(void *base_addr, int index,
206− size_t len, const char *name)
205+static struct f2fs_xattr_entry *__find_xattr(void *base_addr,
206+ void *last_base_addr, int index,
207+ size_t len, const char *name)
207208 {
208209 struct f2fs_xattr_entry *entry;
209210
210211 list_for_each_xattr(entry, base_addr) {
212+ if ((void *)(entry) + sizeof(__u32) > last_base_addr ||
213+ (void *)XATTR_NEXT_ENTRY(entry) > last_base_addr)
214+ return NULL;
215+
211216 if (entry->e_name_index != index)
212217 continue;
213218 if (entry->e_name_len != len)
@@ -297,20 +302,22 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage, · 83 unmodified lines
297302 const char *name, struct f2fs_xattr_entry **xe,
298303 void **base_addr, int *base_size)
299304 {
300− void *cur_addr, *txattr_addr, *last_addr = NULL;
305+ void *cur_addr, *txattr_addr, *last_txattr_addr;
306+ void *last_addr = NULL;
301307 nid_t xnid = F2FS_I(inode)->i_xattr_nid;
302− unsigned int size = xnid ? VALID_XATTR_BLOCK_SIZE : 0;
303308 unsigned int inline_size = inline_xattr_size(inode);
304309 int err = 0;
305310
306− if (!size && !inline_size)
311+ if (!xnid && !inline_size)
307312 return -ENODATA;
308313
309− *base_size = inline_size + size + XATTR_PADDING_SIZE;
314+ *base_size = XATTR_SIZE(xnid, inode) + XATTR_PADDING_SIZE;
310315 txattr_addr = f2fs_kzalloc(F2FS_I_SB(inode), *base_size, GFP_NOFS);
311316 if (!txattr_addr)
312317 return -ENOMEM;
313318
319+ last_txattr_addr = (void *)txattr_addr + XATTR_SIZE(xnid, inode);
320+
314321 /* read from inline xattr */
315322 if (inline_size) {
316323 err = read_inline_xattr(inode, ipage, txattr_addr);
@@ -337,7 +344,11 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage, · 20 unmodified lines
337344 else
338345 cur_addr = txattr_addr;
339346
340− *xe = __find_xattr(cur_addr, index, len, name);
347+ *xe = __find_xattr(cur_addr, last_txattr_addr, index, len, name);
348+ if (!*xe) {
349+ err = -EFAULT;
350+ goto out;
351+ }
341352 check:
342353 if (IS_XATTR_LAST_ENTRY(*xe)) {
343354 err = -ENODATA;
@@ -581,7 +592,8 @@ static int __f2fs_setxattr(struct inode *inode, int index, · 237 unmodified lines
581592 struct page *ipage, int flags)
582593 {
583594 struct f2fs_xattr_entry *here, *last;
584− void *base_addr;
595+ void *base_addr, *last_base_addr;
596+ nid_t xnid = F2FS_I(inode)->i_xattr_nid;
585597 int found, newsize;
586598 size_t len;
587599 __u32 new_hsize;
@@ -605,8 +617,14 @@ static int __f2fs_setxattr(struct inode *inode, int index, · 17 unmodified lines
605617 if (error)
606618 return error;
607619
620+ last_base_addr = (void *)base_addr + XATTR_SIZE(xnid, inode);
621+
608622 /* find entry with wanted name. */
609− here = __find_xattr(base_addr, index, len, name);
623+ here = __find_xattr(base_addr, last_base_addr, index, len, name);
624+ if (!here) {
625+ error = -EFAULT;
626+ goto exit;
627+ }
610628
611629 found = IS_XATTR_LAST_ENTRY(here) ? 0 : 1;
612630
fs/f2fs/xattr.h+2−0
@@ -71,6 +71,8 @@ struct f2fs_xattr_entry { · 70 unmodified lines
7171 entry = XATTR_NEXT_ENTRY(entry))
7272 #define VALID_XATTR_BLOCK_SIZE (PAGE_SIZE - sizeof(struct node_footer))
7373 #define XATTR_PADDING_SIZE (sizeof(__u32))
74+#define XATTR_SIZE(x,i) (((x) ? VALID_XATTR_BLOCK_SIZE : 0) + \
75+ (inline_xattr_size(i)))
7476 #define MIN_OFFSET(i) XATTR_ALIGN(inline_xattr_size(i) + \
7577 VALID_XATTR_BLOCK_SIZE)
7678
include/linux/f2fs_fs.h+8−3
@@ -164,6 +164,10 @@ struct f2fs_checkpoint { · 163 unmodified lines
164164 unsigned char sit_nat_version_bitmap[1];
165165 } __packed;
166166
167+#define CP_CHKSUM_OFFSET 4092 /* default chksum offset in checkpoint */
168+#define CP_MIN_CHKSUM_OFFSET \
169+ (offsetof(struct f2fs_checkpoint, sit_nat_version_bitmap))
170+
167171 /*
168172 * For orphan inode management
169173 */
@@ -198,11 +202,12 @@ struct f2fs_extent { · 28 unmodified lines
198202 get_extra_isize(inode))
199203 #define DEF_NIDS_PER_INODE 5 /* Node IDs in an Inode */
200204 #define ADDRS_PER_INODE(inode) addrs_per_inode(inode)
201−#define ADDRS_PER_BLOCK 1018 /* Address Pointers in a Direct Block */
205+#define DEF_ADDRS_PER_BLOCK 1018 /* Address Pointers in a Direct Block */
206+#define ADDRS_PER_BLOCK(inode) addrs_per_block(inode)
202207 #define NIDS_PER_BLOCK 1018 /* Node IDs in an Indirect Block */
203208
204209 #define ADDRS_PER_PAGE(page, inode) \
205− (IS_INODE(page) ? ADDRS_PER_INODE(inode) : ADDRS_PER_BLOCK)
210+ (IS_INODE(page) ? ADDRS_PER_INODE(inode) : ADDRS_PER_BLOCK(inode))
206211
207212 #define NODE_DIR1_BLOCK (DEF_ADDRS_PER_INODE + 1)
208213 #define NODE_DIR2_BLOCK (DEF_ADDRS_PER_INODE + 2)
@@ -267,7 +272,7 @@ struct f2fs_inode { · 58 unmodified lines
267272 } __packed;
268273
269274 struct direct_node {
270− __le32 addr[ADDRS_PER_BLOCK]; /* array of data block address */
275+ __le32 addr[DEF_ADDRS_PER_BLOCK]; /* array of data block address */
271276 } __packed;
272277
273278 struct indirect_node {
include/trace/events/f2fs.h+57−0
@@ -533,6 +533,37 @@ TRACE_EVENT(f2fs_truncate_partial_nodes, · 532 unmodified lines
533533 __entry->err)
534534 );
535535
536+TRACE_EVENT(f2fs_file_write_iter,
537+
538+ TP_PROTO(struct inode *inode, unsigned long offset,
539+ unsigned long length, int ret),
540+
541+ TP_ARGS(inode, offset, length, ret),
542+
543+ TP_STRUCT__entry(
544+ __field(dev_t, dev)
545+ __field(ino_t, ino)
546+ __field(unsigned long, offset)
547+ __field(unsigned long, length)
548+ __field(int, ret)
549+ ),
550+
551+ TP_fast_assign(
552+ __entry->dev = inode->i_sb->s_dev;
553+ __entry->ino = inode->i_ino;
554+ __entry->offset = offset;
555+ __entry->length = length;
556+ __entry->ret = ret;
557+ ),
558+
559+ TP_printk("dev = (%d,%d), ino = %lu, "
560+ "offset = %lu, length = %lu, written(err) = %d",
561+ show_dev_ino(__entry),
562+ __entry->offset,
563+ __entry->length,
564+ __entry->ret)
565+);
566+
536567 TRACE_EVENT(f2fs_map_blocks,
537568 TP_PROTO(struct inode *inode, struct f2fs_map_blocks *map, int ret),
538569
@@ -1253,6 +1284,32 @@ DEFINE_EVENT(f2fs__page, f2fs_commit_inmem_page, · 714 unmodified lines
12531284 TP_ARGS(page, type)
12541285 );
12551286
1287+TRACE_EVENT(f2fs_filemap_fault,
1288+
1289+ TP_PROTO(struct inode *inode, pgoff_t index, unsigned long ret),
1290+
1291+ TP_ARGS(inode, index, ret),
1292+
1293+ TP_STRUCT__entry(
1294+ __field(dev_t, dev)
1295+ __field(ino_t, ino)
1296+ __field(pgoff_t, index)
1297+ __field(unsigned long, ret)
1298+ ),
1299+
1300+ TP_fast_assign(
1301+ __entry->dev = inode->i_sb->s_dev;
1302+ __entry->ino = inode->i_ino;
1303+ __entry->index = index;
1304+ __entry->ret = ret;
1305+ ),
1306+
1307+ TP_printk("dev = (%d,%d), ino = %lu, index = %lu, ret = %lx",
1308+ show_dev_ino(__entry),
1309+ (unsigned long)__entry->index,
1310+ __entry->ret)
1311+);
1312+
12561313 TRACE_EVENT(f2fs_writepages,
12571314
12581315 TP_PROTO(struct inode *inode, struct writeback_control *wbc, int type),

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t