Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'ext4_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4

Pull ext4 updates from Ted Ts'o:
"Ext4 regression and bug fixes"

* tag 'ext4_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4:
ext4: inline jbd2_journal_[un]register_shrinker()
ext4: fix flags validity checking for EXT4_IOC_CHECKPOINT
ext4: fix possible UAF when remounting r/o a mmp-protected file system
ext4: use ext4_grp_locked_error in mb_find_extent
ext4: fix WARN_ON_ONCE(!buffer_uptodate) after an error writing the superblock
Revert "ext4: consolidate checks for resize of bigalloc into ext4_resize_begin"

+115 -132
+1 -1
fs/ext4/ext4_jbd2.c
··· 327 327 328 328 set_buffer_meta(bh); 329 329 set_buffer_prio(bh); 330 + set_buffer_uptodate(bh); 330 331 if (ext4_handle_valid(handle)) { 331 332 err = jbd2_journal_dirty_metadata(handle, bh); 332 333 /* Errors can only happen due to aborted journal or a nasty bug */ ··· 356 355 err); 357 356 } 358 357 } else { 359 - set_buffer_uptodate(bh); 360 358 if (inode) 361 359 mark_buffer_dirty_inode(bh, inode); 362 360 else
+15 -1
fs/ext4/ioctl.c
··· 692 692 if (err) 693 693 return err; 694 694 695 + if (ext4_has_feature_bigalloc(sb)) { 696 + ext4_msg(sb, KERN_ERR, 697 + "Online resizing not supported with bigalloc"); 698 + err = -EOPNOTSUPP; 699 + goto group_add_out; 700 + } 701 + 695 702 err = mnt_want_write_file(file); 696 703 if (err) 697 704 goto group_add_out; ··· 823 816 if (!EXT4_SB(sb)->s_journal) 824 817 return -ENODEV; 825 818 826 - if (flags & ~JBD2_JOURNAL_FLUSH_VALID) 819 + if (flags & ~EXT4_IOC_CHECKPOINT_FLAG_VALID) 827 820 return -EINVAL; 828 821 829 822 q = bdev_get_queue(EXT4_SB(sb)->s_journal->j_dev); ··· 918 911 919 912 if (get_user(n_blocks_count, (__u32 __user *)arg)) { 920 913 err = -EFAULT; 914 + goto group_extend_out; 915 + } 916 + 917 + if (ext4_has_feature_bigalloc(sb)) { 918 + ext4_msg(sb, KERN_ERR, 919 + "Online resizing not supported with bigalloc"); 920 + err = -EOPNOTSUPP; 921 921 goto group_extend_out; 922 922 } 923 923
+5 -4
fs/ext4/mballoc.c
··· 1909 1909 if (ex->fe_start + ex->fe_len > EXT4_CLUSTERS_PER_GROUP(e4b->bd_sb)) { 1910 1910 /* Should never happen! (but apparently sometimes does?!?) */ 1911 1911 WARN_ON(1); 1912 - ext4_error(e4b->bd_sb, "corruption or bug in mb_find_extent " 1913 - "block=%d, order=%d needed=%d ex=%u/%d/%d@%u", 1914 - block, order, needed, ex->fe_group, ex->fe_start, 1915 - ex->fe_len, ex->fe_logical); 1912 + ext4_grp_locked_error(e4b->bd_sb, e4b->bd_group, 0, 0, 1913 + "corruption or bug in mb_find_extent " 1914 + "block=%d, order=%d needed=%d ex=%u/%d/%d@%u", 1915 + block, order, needed, ex->fe_group, ex->fe_start, 1916 + ex->fe_len, ex->fe_logical); 1916 1917 ex->fe_len = 0; 1917 1918 ex->fe_start = 0; 1918 1919 ex->fe_group = 0;
+15 -16
fs/ext4/mmp.c
··· 156 156 memcpy(mmp->mmp_nodename, init_utsname()->nodename, 157 157 sizeof(mmp->mmp_nodename)); 158 158 159 - while (!kthread_should_stop()) { 159 + while (!kthread_should_stop() && !sb_rdonly(sb)) { 160 + if (!ext4_has_feature_mmp(sb)) { 161 + ext4_warning(sb, "kmmpd being stopped since MMP feature" 162 + " has been disabled."); 163 + goto wait_to_exit; 164 + } 160 165 if (++seq > EXT4_MMP_SEQ_MAX) 161 166 seq = 1; 162 167 ··· 181 176 } 182 177 failed_writes++; 183 178 } 184 - 185 - if (!(le32_to_cpu(es->s_feature_incompat) & 186 - EXT4_FEATURE_INCOMPAT_MMP)) { 187 - ext4_warning(sb, "kmmpd being stopped since MMP feature" 188 - " has been disabled."); 189 - goto exit_thread; 190 - } 191 - 192 - if (sb_rdonly(sb)) 193 - break; 194 179 195 180 diff = jiffies - last_update_time; 196 181 if (diff < mmp_update_interval * HZ) ··· 202 207 ext4_error_err(sb, -retval, 203 208 "error reading MMP data: %d", 204 209 retval); 205 - goto exit_thread; 210 + goto wait_to_exit; 206 211 } 207 212 208 213 mmp_check = (struct mmp_struct *)(bh_check->b_data); ··· 216 221 ext4_error_err(sb, EBUSY, "abort"); 217 222 put_bh(bh_check); 218 223 retval = -EBUSY; 219 - goto exit_thread; 224 + goto wait_to_exit; 220 225 } 221 226 put_bh(bh_check); 222 227 } ··· 239 244 240 245 retval = write_mmp_block(sb, bh); 241 246 242 - exit_thread: 247 + wait_to_exit: 248 + while (!kthread_should_stop()) { 249 + set_current_state(TASK_INTERRUPTIBLE); 250 + if (!kthread_should_stop()) 251 + schedule(); 252 + } 253 + set_current_state(TASK_RUNNING); 243 254 return retval; 244 255 } 245 256 ··· 392 391 brelse(bh); 393 392 return 1; 394 393 } 395 - 396 -
-4
fs/ext4/resize.c
··· 74 74 return -EPERM; 75 75 } 76 76 77 - if (ext4_has_feature_bigalloc(sb)) { 78 - ext4_msg(sb, KERN_ERR, "Online resizing not supported with bigalloc"); 79 - return -EOPNOTSUPP; 80 - } 81 77 if (ext4_has_feature_sparse_super2(sb)) { 82 78 ext4_msg(sb, KERN_ERR, "Online resizing not supported with sparse_super2"); 83 79 return -EOPNOTSUPP;
+15 -11
fs/ext4/super.c
··· 705 705 * ext4 error handling code during handling of previous errors. 706 706 */ 707 707 if (!sb_rdonly(sbi->s_sb) && journal) { 708 + struct buffer_head *sbh = sbi->s_sbh; 708 709 handle = jbd2_journal_start(journal, 1); 709 710 if (IS_ERR(handle)) 710 711 goto write_directly; 711 - if (jbd2_journal_get_write_access(handle, sbi->s_sbh)) { 712 + if (jbd2_journal_get_write_access(handle, sbh)) { 712 713 jbd2_journal_stop(handle); 713 714 goto write_directly; 714 715 } 715 716 ext4_update_super(sbi->s_sb); 716 - if (jbd2_journal_dirty_metadata(handle, sbi->s_sbh)) { 717 + if (buffer_write_io_error(sbh) || !buffer_uptodate(sbh)) { 718 + ext4_msg(sbi->s_sb, KERN_ERR, "previous I/O error to " 719 + "superblock detected"); 720 + clear_buffer_write_io_error(sbh); 721 + set_buffer_uptodate(sbh); 722 + } 723 + 724 + if (jbd2_journal_dirty_metadata(handle, sbh)) { 717 725 jbd2_journal_stop(handle); 718 726 goto write_directly; 719 727 } ··· 1184 1176 ext4_unregister_sysfs(sb); 1185 1177 1186 1178 if (sbi->s_journal) { 1187 - jbd2_journal_unregister_shrinker(sbi->s_journal); 1188 1179 aborted = is_journal_aborted(sbi->s_journal); 1189 1180 err = jbd2_journal_destroy(sbi->s_journal); 1190 1181 sbi->s_journal = NULL; ··· 5175 5168 sbi->s_ea_block_cache = NULL; 5176 5169 5177 5170 if (sbi->s_journal) { 5178 - jbd2_journal_unregister_shrinker(sbi->s_journal); 5179 5171 jbd2_journal_destroy(sbi->s_journal); 5180 5172 sbi->s_journal = NULL; 5181 5173 } ··· 5498 5492 5499 5493 /* Make sure we flush the recovery flag to disk. */ 5500 5494 ext4_commit_super(sb); 5501 - } 5502 - 5503 - err = jbd2_journal_register_shrinker(journal); 5504 - if (err) { 5505 - EXT4_SB(sb)->s_journal = NULL; 5506 - goto err_out; 5507 5495 } 5508 5496 5509 5497 return 0; ··· 5985 5985 */ 5986 5986 ext4_mark_recovery_complete(sb, es); 5987 5987 } 5988 - ext4_stop_mmpd(sbi); 5989 5988 } else { 5990 5989 /* Make sure we can mount this feature set readwrite */ 5991 5990 if (ext4_has_feature_readonly(sb) || ··· 6098 6099 if (!test_opt(sb, BLOCK_VALIDITY) && sbi->s_system_blks) 6099 6100 ext4_release_system_zone(sb); 6100 6101 6102 + if (!ext4_has_feature_mmp(sb) || sb_rdonly(sb)) 6103 + ext4_stop_mmpd(sbi); 6104 + 6101 6105 /* 6102 6106 * Some options can be enabled by ext4 and/or by VFS mount flag 6103 6107 * either way we need to make sure it matches in both *flags and ··· 6134 6132 for (i = 0; i < EXT4_MAXQUOTAS; i++) 6135 6133 kfree(to_free[i]); 6136 6134 #endif 6135 + if (!ext4_has_feature_mmp(sb) || sb_rdonly(sb)) 6136 + ext4_stop_mmpd(sbi); 6137 6137 kfree(orig_data); 6138 6138 return err; 6139 6139 }
+2 -2
fs/jbd2/checkpoint.c
··· 701 701 702 702 __buffer_unlink(jh); 703 703 jh->b_cp_transaction = NULL; 704 - percpu_counter_dec(&journal->j_jh_shrink_count); 704 + percpu_counter_dec(&journal->j_checkpoint_jh_count); 705 705 jbd2_journal_put_journal_head(jh); 706 706 707 707 /* Is this transaction empty? */ ··· 764 764 jh->b_cpnext->b_cpprev = jh; 765 765 } 766 766 transaction->t_checkpoint_list = jh; 767 - percpu_counter_inc(&transaction->t_journal->j_jh_shrink_count); 767 + percpu_counter_inc(&transaction->t_journal->j_checkpoint_jh_count); 768 768 } 769 769 770 770 /*
+60 -89
fs/jbd2/journal.c
··· 1283 1283 return sizeof(journal_block_tag_t) - 4; 1284 1284 } 1285 1285 1286 + /** 1287 + * jbd2_journal_shrink_scan() 1288 + * 1289 + * Scan the checkpointed buffer on the checkpoint list and release the 1290 + * journal_head. 1291 + */ 1292 + static unsigned long jbd2_journal_shrink_scan(struct shrinker *shrink, 1293 + struct shrink_control *sc) 1294 + { 1295 + journal_t *journal = container_of(shrink, journal_t, j_shrinker); 1296 + unsigned long nr_to_scan = sc->nr_to_scan; 1297 + unsigned long nr_shrunk; 1298 + unsigned long count; 1299 + 1300 + count = percpu_counter_read_positive(&journal->j_checkpoint_jh_count); 1301 + trace_jbd2_shrink_scan_enter(journal, sc->nr_to_scan, count); 1302 + 1303 + nr_shrunk = jbd2_journal_shrink_checkpoint_list(journal, &nr_to_scan); 1304 + 1305 + count = percpu_counter_read_positive(&journal->j_checkpoint_jh_count); 1306 + trace_jbd2_shrink_scan_exit(journal, nr_to_scan, nr_shrunk, count); 1307 + 1308 + return nr_shrunk; 1309 + } 1310 + 1311 + /** 1312 + * jbd2_journal_shrink_count() 1313 + * 1314 + * Count the number of checkpoint buffers on the checkpoint list. 1315 + */ 1316 + static unsigned long jbd2_journal_shrink_count(struct shrinker *shrink, 1317 + struct shrink_control *sc) 1318 + { 1319 + journal_t *journal = container_of(shrink, journal_t, j_shrinker); 1320 + unsigned long count; 1321 + 1322 + count = percpu_counter_read_positive(&journal->j_checkpoint_jh_count); 1323 + trace_jbd2_shrink_count(journal, sc->nr_to_scan, count); 1324 + 1325 + return count; 1326 + } 1327 + 1286 1328 /* 1287 1329 * Management for journal control blocks: functions to create and 1288 1330 * destroy journal_t structures, and to initialise and read existing ··· 1403 1361 journal->j_sb_buffer = bh; 1404 1362 journal->j_superblock = (journal_superblock_t *)bh->b_data; 1405 1363 1364 + journal->j_shrink_transaction = NULL; 1365 + journal->j_shrinker.scan_objects = jbd2_journal_shrink_scan; 1366 + journal->j_shrinker.count_objects = jbd2_journal_shrink_count; 1367 + journal->j_shrinker.seeks = DEFAULT_SEEKS; 1368 + journal->j_shrinker.batch = journal->j_max_transaction_buffers; 1369 + 1370 + if (percpu_counter_init(&journal->j_checkpoint_jh_count, 0, GFP_KERNEL)) 1371 + goto err_cleanup; 1372 + 1373 + if (register_shrinker(&journal->j_shrinker)) { 1374 + percpu_counter_destroy(&journal->j_checkpoint_jh_count); 1375 + goto err_cleanup; 1376 + } 1406 1377 return journal; 1407 1378 1408 1379 err_cleanup: 1380 + brelse(journal->j_sb_buffer); 1409 1381 kfree(journal->j_wbuf); 1410 1382 jbd2_journal_destroy_revoke(journal); 1411 1383 kfree(journal); ··· 2107 2051 } 2108 2052 2109 2053 /** 2110 - * jbd2_journal_shrink_scan() 2111 - * 2112 - * Scan the checkpointed buffer on the checkpoint list and release the 2113 - * journal_head. 2114 - */ 2115 - static unsigned long jbd2_journal_shrink_scan(struct shrinker *shrink, 2116 - struct shrink_control *sc) 2117 - { 2118 - journal_t *journal = container_of(shrink, journal_t, j_shrinker); 2119 - unsigned long nr_to_scan = sc->nr_to_scan; 2120 - unsigned long nr_shrunk; 2121 - unsigned long count; 2122 - 2123 - count = percpu_counter_read_positive(&journal->j_jh_shrink_count); 2124 - trace_jbd2_shrink_scan_enter(journal, sc->nr_to_scan, count); 2125 - 2126 - nr_shrunk = jbd2_journal_shrink_checkpoint_list(journal, &nr_to_scan); 2127 - 2128 - count = percpu_counter_read_positive(&journal->j_jh_shrink_count); 2129 - trace_jbd2_shrink_scan_exit(journal, nr_to_scan, nr_shrunk, count); 2130 - 2131 - return nr_shrunk; 2132 - } 2133 - 2134 - /** 2135 - * jbd2_journal_shrink_count() 2136 - * 2137 - * Count the number of checkpoint buffers on the checkpoint list. 2138 - */ 2139 - static unsigned long jbd2_journal_shrink_count(struct shrinker *shrink, 2140 - struct shrink_control *sc) 2141 - { 2142 - journal_t *journal = container_of(shrink, journal_t, j_shrinker); 2143 - unsigned long count; 2144 - 2145 - count = percpu_counter_read_positive(&journal->j_jh_shrink_count); 2146 - trace_jbd2_shrink_count(journal, sc->nr_to_scan, count); 2147 - 2148 - return count; 2149 - } 2150 - 2151 - /** 2152 - * jbd2_journal_register_shrinker() 2153 - * @journal: Journal to act on. 2154 - * 2155 - * Init a percpu counter to record the checkpointed buffers on the checkpoint 2156 - * list and register a shrinker to release their journal_head. 2157 - */ 2158 - int jbd2_journal_register_shrinker(journal_t *journal) 2159 - { 2160 - int err; 2161 - 2162 - journal->j_shrink_transaction = NULL; 2163 - 2164 - err = percpu_counter_init(&journal->j_jh_shrink_count, 0, GFP_KERNEL); 2165 - if (err) 2166 - return err; 2167 - 2168 - journal->j_shrinker.scan_objects = jbd2_journal_shrink_scan; 2169 - journal->j_shrinker.count_objects = jbd2_journal_shrink_count; 2170 - journal->j_shrinker.seeks = DEFAULT_SEEKS; 2171 - journal->j_shrinker.batch = journal->j_max_transaction_buffers; 2172 - 2173 - err = register_shrinker(&journal->j_shrinker); 2174 - if (err) { 2175 - percpu_counter_destroy(&journal->j_jh_shrink_count); 2176 - return err; 2177 - } 2178 - 2179 - return 0; 2180 - } 2181 - EXPORT_SYMBOL(jbd2_journal_register_shrinker); 2182 - 2183 - /** 2184 - * jbd2_journal_unregister_shrinker() 2185 - * @journal: Journal to act on. 2186 - * 2187 - * Unregister the checkpointed buffer shrinker and destroy the percpu counter. 2188 - */ 2189 - void jbd2_journal_unregister_shrinker(journal_t *journal) 2190 - { 2191 - percpu_counter_destroy(&journal->j_jh_shrink_count); 2192 - unregister_shrinker(&journal->j_shrinker); 2193 - } 2194 - EXPORT_SYMBOL(jbd2_journal_unregister_shrinker); 2195 - 2196 - /** 2197 2054 * jbd2_journal_destroy() - Release a journal_t structure. 2198 2055 * @journal: Journal to act on. 2199 2056 * ··· 2178 2209 brelse(journal->j_sb_buffer); 2179 2210 } 2180 2211 2181 - jbd2_journal_unregister_shrinker(journal); 2182 - 2212 + if (journal->j_shrinker.flags & SHRINKER_REGISTERED) { 2213 + percpu_counter_destroy(&journal->j_checkpoint_jh_count); 2214 + unregister_shrinker(&journal->j_shrinker); 2215 + } 2183 2216 if (journal->j_proc_entry) 2184 2217 jbd2_stats_proc_exit(journal); 2185 2218 iput(journal->j_inode);
+2 -4
include/linux/jbd2.h
··· 918 918 struct shrinker j_shrinker; 919 919 920 920 /** 921 - * @j_jh_shrink_count: 921 + * @j_checkpoint_jh_count: 922 922 * 923 923 * Number of journal buffers on the checkpoint list. [j_list_lock] 924 924 */ 925 - struct percpu_counter j_jh_shrink_count; 925 + struct percpu_counter j_checkpoint_jh_count; 926 926 927 927 /** 928 928 * @j_shrink_transaction: ··· 1556 1556 (journal_t *, unsigned long, unsigned long, unsigned long); 1557 1557 extern void jbd2_journal_clear_features 1558 1558 (journal_t *, unsigned long, unsigned long, unsigned long); 1559 - extern int jbd2_journal_register_shrinker(journal_t *journal); 1560 - extern void jbd2_journal_unregister_shrinker(journal_t *journal); 1561 1559 extern int jbd2_journal_load (journal_t *journal); 1562 1560 extern int jbd2_journal_destroy (journal_t *); 1563 1561 extern int jbd2_journal_recover (journal_t *journal);