| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * linux/fs/buffer.c |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 47 | 48 | #include <linux/sched/mm.h> |
|---|
| 48 | 49 | #include <trace/events/block.h> |
|---|
| 49 | 50 | #include <linux/fscrypt.h> |
|---|
| 51 | + |
|---|
| 52 | +#include "internal.h" |
|---|
| 50 | 53 | |
|---|
| 51 | 54 | static int fsync_buffers_list(spinlock_t *lock, struct list_head *list); |
|---|
| 52 | 55 | static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh, |
|---|
| .. | .. |
|---|
| 120 | 123 | } |
|---|
| 121 | 124 | EXPORT_SYMBOL(__wait_on_buffer); |
|---|
| 122 | 125 | |
|---|
| 123 | | -static void |
|---|
| 124 | | -__clear_page_buffers(struct page *page) |
|---|
| 125 | | -{ |
|---|
| 126 | | - ClearPagePrivate(page); |
|---|
| 127 | | - set_page_private(page, 0); |
|---|
| 128 | | - put_page(page); |
|---|
| 129 | | -} |
|---|
| 130 | | - |
|---|
| 131 | 126 | static void buffer_io_error(struct buffer_head *bh, char *msg) |
|---|
| 132 | 127 | { |
|---|
| 133 | 128 | if (!test_bit(BH_Quiet, &bh->b_state)) |
|---|
| .. | .. |
|---|
| 178 | 173 | unlock_buffer(bh); |
|---|
| 179 | 174 | put_bh(bh); |
|---|
| 180 | 175 | } |
|---|
| 181 | | -EXPORT_SYMBOL(end_buffer_write_sync); |
|---|
| 176 | +EXPORT_SYMBOL_NS(end_buffer_write_sync, ANDROID_GKI_VFS_EXPORT_ONLY); |
|---|
| 182 | 177 | |
|---|
| 183 | 178 | /* |
|---|
| 184 | 179 | * Various filesystems appear to want __find_get_block to be non-blocking. |
|---|
| .. | .. |
|---|
| 246 | 241 | return ret; |
|---|
| 247 | 242 | } |
|---|
| 248 | 243 | |
|---|
| 249 | | -/* |
|---|
| 250 | | - * I/O completion handler for block_read_full_page() - pages |
|---|
| 251 | | - * which come unlocked at the end of I/O. |
|---|
| 252 | | - */ |
|---|
| 253 | 244 | static void end_buffer_async_read(struct buffer_head *bh, int uptodate) |
|---|
| 254 | 245 | { |
|---|
| 255 | 246 | unsigned long flags; |
|---|
| .. | .. |
|---|
| 275 | 266 | * decide that the page is now completely done. |
|---|
| 276 | 267 | */ |
|---|
| 277 | 268 | first = page_buffers(page); |
|---|
| 278 | | - flags = bh_uptodate_lock_irqsave(first); |
|---|
| 269 | + spin_lock_irqsave(&first->b_uptodate_lock, flags); |
|---|
| 279 | 270 | clear_buffer_async_read(bh); |
|---|
| 280 | 271 | unlock_buffer(bh); |
|---|
| 281 | 272 | tmp = bh; |
|---|
| .. | .. |
|---|
| 288 | 279 | } |
|---|
| 289 | 280 | tmp = tmp->b_this_page; |
|---|
| 290 | 281 | } while (tmp != bh); |
|---|
| 291 | | - bh_uptodate_unlock_irqrestore(first, flags); |
|---|
| 282 | + spin_unlock_irqrestore(&first->b_uptodate_lock, flags); |
|---|
| 292 | 283 | |
|---|
| 293 | 284 | /* |
|---|
| 294 | 285 | * If none of the buffers had errors and they are all |
|---|
| .. | .. |
|---|
| 300 | 291 | return; |
|---|
| 301 | 292 | |
|---|
| 302 | 293 | still_busy: |
|---|
| 303 | | - bh_uptodate_unlock_irqrestore(first, flags); |
|---|
| 294 | + spin_unlock_irqrestore(&first->b_uptodate_lock, flags); |
|---|
| 295 | + return; |
|---|
| 296 | +} |
|---|
| 297 | + |
|---|
| 298 | +struct decrypt_bh_ctx { |
|---|
| 299 | + struct work_struct work; |
|---|
| 300 | + struct buffer_head *bh; |
|---|
| 301 | +}; |
|---|
| 302 | + |
|---|
| 303 | +static void decrypt_bh(struct work_struct *work) |
|---|
| 304 | +{ |
|---|
| 305 | + struct decrypt_bh_ctx *ctx = |
|---|
| 306 | + container_of(work, struct decrypt_bh_ctx, work); |
|---|
| 307 | + struct buffer_head *bh = ctx->bh; |
|---|
| 308 | + int err; |
|---|
| 309 | + |
|---|
| 310 | + err = fscrypt_decrypt_pagecache_blocks(bh->b_page, bh->b_size, |
|---|
| 311 | + bh_offset(bh)); |
|---|
| 312 | + end_buffer_async_read(bh, err == 0); |
|---|
| 313 | + kfree(ctx); |
|---|
| 314 | +} |
|---|
| 315 | + |
|---|
| 316 | +/* |
|---|
| 317 | + * I/O completion handler for block_read_full_page() - pages |
|---|
| 318 | + * which come unlocked at the end of I/O. |
|---|
| 319 | + */ |
|---|
| 320 | +static void end_buffer_async_read_io(struct buffer_head *bh, int uptodate) |
|---|
| 321 | +{ |
|---|
| 322 | + /* Decrypt if needed */ |
|---|
| 323 | + if (uptodate && |
|---|
| 324 | + fscrypt_inode_uses_fs_layer_crypto(bh->b_page->mapping->host)) { |
|---|
| 325 | + struct decrypt_bh_ctx *ctx = kmalloc(sizeof(*ctx), GFP_ATOMIC); |
|---|
| 326 | + |
|---|
| 327 | + if (ctx) { |
|---|
| 328 | + INIT_WORK(&ctx->work, decrypt_bh); |
|---|
| 329 | + ctx->bh = bh; |
|---|
| 330 | + fscrypt_enqueue_decrypt_work(&ctx->work); |
|---|
| 331 | + return; |
|---|
| 332 | + } |
|---|
| 333 | + uptodate = 0; |
|---|
| 334 | + } |
|---|
| 335 | + end_buffer_async_read(bh, uptodate); |
|---|
| 304 | 336 | } |
|---|
| 305 | 337 | |
|---|
| 306 | 338 | /* |
|---|
| .. | .. |
|---|
| 327 | 359 | } |
|---|
| 328 | 360 | |
|---|
| 329 | 361 | first = page_buffers(page); |
|---|
| 330 | | - flags = bh_uptodate_lock_irqsave(first); |
|---|
| 362 | + spin_lock_irqsave(&first->b_uptodate_lock, flags); |
|---|
| 331 | 363 | |
|---|
| 332 | 364 | clear_buffer_async_write(bh); |
|---|
| 333 | 365 | unlock_buffer(bh); |
|---|
| .. | .. |
|---|
| 339 | 371 | } |
|---|
| 340 | 372 | tmp = tmp->b_this_page; |
|---|
| 341 | 373 | } |
|---|
| 342 | | - bh_uptodate_unlock_irqrestore(first, flags); |
|---|
| 374 | + spin_unlock_irqrestore(&first->b_uptodate_lock, flags); |
|---|
| 343 | 375 | end_page_writeback(page); |
|---|
| 344 | 376 | return; |
|---|
| 345 | 377 | |
|---|
| 346 | 378 | still_busy: |
|---|
| 347 | | - bh_uptodate_unlock_irqrestore(first, flags); |
|---|
| 379 | + spin_unlock_irqrestore(&first->b_uptodate_lock, flags); |
|---|
| 380 | + return; |
|---|
| 348 | 381 | } |
|---|
| 349 | 382 | EXPORT_SYMBOL(end_buffer_async_write); |
|---|
| 350 | 383 | |
|---|
| .. | .. |
|---|
| 371 | 404 | */ |
|---|
| 372 | 405 | static void mark_buffer_async_read(struct buffer_head *bh) |
|---|
| 373 | 406 | { |
|---|
| 374 | | - bh->b_end_io = end_buffer_async_read; |
|---|
| 407 | + bh->b_end_io = end_buffer_async_read_io; |
|---|
| 375 | 408 | set_buffer_async_read(bh); |
|---|
| 376 | 409 | } |
|---|
| 377 | 410 | |
|---|
| .. | .. |
|---|
| 386 | 419 | { |
|---|
| 387 | 420 | mark_buffer_async_write_endio(bh, end_buffer_async_write); |
|---|
| 388 | 421 | } |
|---|
| 389 | | -EXPORT_SYMBOL(mark_buffer_async_write); |
|---|
| 422 | +EXPORT_SYMBOL_NS(mark_buffer_async_write, ANDROID_GKI_VFS_EXPORT_ONLY); |
|---|
| 390 | 423 | |
|---|
| 391 | 424 | |
|---|
| 392 | 425 | /* |
|---|
| .. | .. |
|---|
| 490 | 523 | |
|---|
| 491 | 524 | void emergency_thaw_bdev(struct super_block *sb) |
|---|
| 492 | 525 | { |
|---|
| 493 | | - while (sb->s_bdev && !thaw_bdev(sb->s_bdev, sb)) |
|---|
| 526 | + while (sb->s_bdev && !thaw_bdev(sb->s_bdev)) |
|---|
| 494 | 527 | printk(KERN_WARNING "Emergency Thaw on %pg\n", sb->s_bdev); |
|---|
| 495 | 528 | } |
|---|
| 496 | 529 | |
|---|
| .. | .. |
|---|
| 556 | 589 | EXPORT_SYMBOL(mark_buffer_dirty_inode); |
|---|
| 557 | 590 | |
|---|
| 558 | 591 | /* |
|---|
| 559 | | - * Mark the page dirty, and set it dirty in the radix tree, and mark the inode |
|---|
| 592 | + * Mark the page dirty, and set it dirty in the page cache, and mark the inode |
|---|
| 560 | 593 | * dirty. |
|---|
| 561 | 594 | * |
|---|
| 562 | 595 | * If warn is true, then emit a warning if the page is not uptodate and has |
|---|
| .. | .. |
|---|
| 573 | 606 | if (page->mapping) { /* Race with truncate? */ |
|---|
| 574 | 607 | WARN_ON_ONCE(warn && !PageUptodate(page)); |
|---|
| 575 | 608 | account_page_dirtied(page, mapping); |
|---|
| 576 | | - radix_tree_tag_set(&mapping->i_pages, |
|---|
| 577 | | - page_index(page), PAGECACHE_TAG_DIRTY); |
|---|
| 609 | + __xa_set_mark(&mapping->i_pages, page_index(page), |
|---|
| 610 | + PAGECACHE_TAG_DIRTY); |
|---|
| 578 | 611 | } |
|---|
| 579 | 612 | xa_unlock_irqrestore(&mapping->i_pages, flags); |
|---|
| 580 | 613 | } |
|---|
| .. | .. |
|---|
| 641 | 674 | |
|---|
| 642 | 675 | return newly_dirty; |
|---|
| 643 | 676 | } |
|---|
| 644 | | -EXPORT_SYMBOL(__set_page_dirty_buffers); |
|---|
| 677 | +EXPORT_SYMBOL_NS(__set_page_dirty_buffers, ANDROID_GKI_VFS_EXPORT_ONLY); |
|---|
| 645 | 678 | |
|---|
| 646 | 679 | /* |
|---|
| 647 | 680 | * Write out and wait upon a list of buffers. |
|---|
| .. | .. |
|---|
| 809 | 842 | struct buffer_head *bh, *head; |
|---|
| 810 | 843 | gfp_t gfp = GFP_NOFS | __GFP_ACCOUNT; |
|---|
| 811 | 844 | long offset; |
|---|
| 812 | | - struct mem_cgroup *memcg; |
|---|
| 845 | + struct mem_cgroup *memcg, *old_memcg; |
|---|
| 813 | 846 | |
|---|
| 814 | 847 | if (retry) |
|---|
| 815 | 848 | gfp |= __GFP_NOFAIL; |
|---|
| 816 | 849 | |
|---|
| 817 | 850 | memcg = get_mem_cgroup_from_page(page); |
|---|
| 818 | | - memalloc_use_memcg(memcg); |
|---|
| 851 | + old_memcg = set_active_memcg(memcg); |
|---|
| 819 | 852 | |
|---|
| 820 | 853 | head = NULL; |
|---|
| 821 | 854 | offset = PAGE_SIZE; |
|---|
| .. | .. |
|---|
| 834 | 867 | set_bh_page(bh, page, offset); |
|---|
| 835 | 868 | } |
|---|
| 836 | 869 | out: |
|---|
| 837 | | - memalloc_unuse_memcg(); |
|---|
| 870 | + set_active_memcg(old_memcg); |
|---|
| 838 | 871 | mem_cgroup_put(memcg); |
|---|
| 839 | 872 | return head; |
|---|
| 840 | 873 | /* |
|---|
| .. | .. |
|---|
| 864 | 897 | bh = bh->b_this_page; |
|---|
| 865 | 898 | } while (bh); |
|---|
| 866 | 899 | tail->b_this_page = head; |
|---|
| 867 | | - attach_page_buffers(page, head); |
|---|
| 900 | + attach_page_private(page, head); |
|---|
| 868 | 901 | } |
|---|
| 869 | 902 | |
|---|
| 870 | 903 | static sector_t blkdev_max_block(struct block_device *bdev, unsigned int size) |
|---|
| .. | .. |
|---|
| 925 | 958 | struct page *page; |
|---|
| 926 | 959 | struct buffer_head *bh; |
|---|
| 927 | 960 | sector_t end_block; |
|---|
| 928 | | - int ret = 0; /* Will call free_more_memory() */ |
|---|
| 961 | + int ret = 0; |
|---|
| 929 | 962 | gfp_t gfp_mask; |
|---|
| 930 | 963 | |
|---|
| 931 | 964 | gfp_mask = mapping_gfp_constraint(inode->i_mapping, ~__GFP_FS) | gfp; |
|---|
| .. | .. |
|---|
| 1044 | 1077 | * The relationship between dirty buffers and dirty pages: |
|---|
| 1045 | 1078 | * |
|---|
| 1046 | 1079 | * Whenever a page has any dirty buffers, the page's dirty bit is set, and |
|---|
| 1047 | | - * the page is tagged dirty in its radix tree. |
|---|
| 1080 | + * the page is tagged dirty in the page cache. |
|---|
| 1048 | 1081 | * |
|---|
| 1049 | 1082 | * At all times, the dirtiness of the buffers represents the dirtiness of |
|---|
| 1050 | 1083 | * subsections of the page. If the page has buffers, the page dirty bit is |
|---|
| .. | .. |
|---|
| 1067 | 1100 | * mark_buffer_dirty - mark a buffer_head as needing writeout |
|---|
| 1068 | 1101 | * @bh: the buffer_head to mark dirty |
|---|
| 1069 | 1102 | * |
|---|
| 1070 | | - * mark_buffer_dirty() will set the dirty bit against the buffer, then set its |
|---|
| 1071 | | - * backing page dirty, then tag the page as dirty in its address_space's radix |
|---|
| 1072 | | - * tree and then attach the address_space's inode to its superblock's dirty |
|---|
| 1103 | + * mark_buffer_dirty() will set the dirty bit against the buffer, then set |
|---|
| 1104 | + * its backing page dirty, then tag the page as dirty in the page cache |
|---|
| 1105 | + * and then attach the address_space's inode to its superblock's dirty |
|---|
| 1073 | 1106 | * inode list. |
|---|
| 1074 | 1107 | * |
|---|
| 1075 | 1108 | * mark_buffer_dirty() is atomic. It takes bh->b_page->mapping->private_lock, |
|---|
| .. | .. |
|---|
| 1108 | 1141 | __mark_inode_dirty(mapping->host, I_DIRTY_PAGES); |
|---|
| 1109 | 1142 | } |
|---|
| 1110 | 1143 | } |
|---|
| 1111 | | -EXPORT_SYMBOL(mark_buffer_dirty); |
|---|
| 1144 | +EXPORT_SYMBOL_NS(mark_buffer_dirty, ANDROID_GKI_VFS_EXPORT_ONLY); |
|---|
| 1112 | 1145 | |
|---|
| 1113 | 1146 | void mark_buffer_write_io_error(struct buffer_head *bh) |
|---|
| 1114 | 1147 | { |
|---|
| 1148 | + struct super_block *sb; |
|---|
| 1149 | + |
|---|
| 1115 | 1150 | set_buffer_write_io_error(bh); |
|---|
| 1116 | 1151 | /* FIXME: do we need to set this in both places? */ |
|---|
| 1117 | 1152 | if (bh->b_page && bh->b_page->mapping) |
|---|
| 1118 | 1153 | mapping_set_error(bh->b_page->mapping, -EIO); |
|---|
| 1119 | 1154 | if (bh->b_assoc_map) |
|---|
| 1120 | 1155 | mapping_set_error(bh->b_assoc_map, -EIO); |
|---|
| 1156 | + rcu_read_lock(); |
|---|
| 1157 | + sb = READ_ONCE(bh->b_bdev->bd_super); |
|---|
| 1158 | + if (sb) |
|---|
| 1159 | + errseq_set(&sb->s_wb_err, -EIO); |
|---|
| 1160 | + rcu_read_unlock(); |
|---|
| 1121 | 1161 | } |
|---|
| 1122 | | -EXPORT_SYMBOL(mark_buffer_write_io_error); |
|---|
| 1162 | +EXPORT_SYMBOL_NS(mark_buffer_write_io_error, ANDROID_GKI_VFS_EXPORT_ONLY); |
|---|
| 1123 | 1163 | |
|---|
| 1124 | 1164 | /* |
|---|
| 1125 | 1165 | * Decrement a buffer_head's reference count. If all buffers against a page |
|---|
| .. | .. |
|---|
| 1136 | 1176 | } |
|---|
| 1137 | 1177 | WARN(1, KERN_ERR "VFS: brelse: Trying to free free buffer\n"); |
|---|
| 1138 | 1178 | } |
|---|
| 1139 | | -EXPORT_SYMBOL(__brelse); |
|---|
| 1179 | +EXPORT_SYMBOL_NS(__brelse, ANDROID_GKI_VFS_EXPORT_ONLY); |
|---|
| 1140 | 1180 | |
|---|
| 1141 | 1181 | /* |
|---|
| 1142 | 1182 | * bforget() is like brelse(), except it discards any |
|---|
| .. | .. |
|---|
| 1155 | 1195 | } |
|---|
| 1156 | 1196 | __brelse(bh); |
|---|
| 1157 | 1197 | } |
|---|
| 1158 | | -EXPORT_SYMBOL(__bforget); |
|---|
| 1198 | +EXPORT_SYMBOL_NS(__bforget, ANDROID_GKI_VFS_EXPORT_ONLY); |
|---|
| 1159 | 1199 | |
|---|
| 1160 | 1200 | static struct buffer_head *__bread_slow(struct buffer_head *bh) |
|---|
| 1161 | 1201 | { |
|---|
| .. | .. |
|---|
| 1224 | 1264 | int i; |
|---|
| 1225 | 1265 | |
|---|
| 1226 | 1266 | check_irqs_on(); |
|---|
| 1267 | + /* |
|---|
| 1268 | + * the refcount of buffer_head in bh_lru prevents dropping the |
|---|
| 1269 | + * attached page(i.e., try_to_free_buffers) so it could cause |
|---|
| 1270 | + * failing page migration. |
|---|
| 1271 | + * Skip putting upcoming bh into bh_lru until migration is done. |
|---|
| 1272 | + */ |
|---|
| 1273 | + if (lru_cache_disabled()) |
|---|
| 1274 | + return; |
|---|
| 1275 | + |
|---|
| 1227 | 1276 | bh_lru_lock(); |
|---|
| 1228 | 1277 | |
|---|
| 1229 | 1278 | b = this_cpu_ptr(&bh_lrus); |
|---|
| .. | .. |
|---|
| 1327 | 1376 | brelse(bh); |
|---|
| 1328 | 1377 | } |
|---|
| 1329 | 1378 | } |
|---|
| 1330 | | -EXPORT_SYMBOL(__breadahead); |
|---|
| 1379 | +EXPORT_SYMBOL_NS(__breadahead, ANDROID_GKI_VFS_EXPORT_ONLY); |
|---|
| 1331 | 1380 | |
|---|
| 1332 | 1381 | void __breadahead_gfp(struct block_device *bdev, sector_t block, unsigned size, |
|---|
| 1333 | 1382 | gfp_t gfp) |
|---|
| .. | .. |
|---|
| 1362 | 1411 | bh = __bread_slow(bh); |
|---|
| 1363 | 1412 | return bh; |
|---|
| 1364 | 1413 | } |
|---|
| 1365 | | -EXPORT_SYMBOL(__bread_gfp); |
|---|
| 1414 | +EXPORT_SYMBOL_NS(__bread_gfp, ANDROID_GKI_VFS_EXPORT_ONLY); |
|---|
| 1366 | 1415 | |
|---|
| 1416 | +static void __invalidate_bh_lrus(struct bh_lru *b) |
|---|
| 1417 | +{ |
|---|
| 1418 | + int i; |
|---|
| 1419 | + |
|---|
| 1420 | + for (i = 0; i < BH_LRU_SIZE; i++) { |
|---|
| 1421 | + brelse(b->bhs[i]); |
|---|
| 1422 | + b->bhs[i] = NULL; |
|---|
| 1423 | + } |
|---|
| 1424 | +} |
|---|
| 1367 | 1425 | /* |
|---|
| 1368 | 1426 | * invalidate_bh_lrus() is called rarely - but not only at unmount. |
|---|
| 1369 | 1427 | * This doesn't race because it runs in each cpu either in irq |
|---|
| .. | .. |
|---|
| 1372 | 1430 | static void invalidate_bh_lru(void *arg) |
|---|
| 1373 | 1431 | { |
|---|
| 1374 | 1432 | struct bh_lru *b = &get_cpu_var(bh_lrus); |
|---|
| 1375 | | - int i; |
|---|
| 1376 | 1433 | |
|---|
| 1377 | | - for (i = 0; i < BH_LRU_SIZE; i++) { |
|---|
| 1378 | | - brelse(b->bhs[i]); |
|---|
| 1379 | | - b->bhs[i] = NULL; |
|---|
| 1380 | | - } |
|---|
| 1434 | + __invalidate_bh_lrus(b); |
|---|
| 1381 | 1435 | put_cpu_var(bh_lrus); |
|---|
| 1382 | 1436 | } |
|---|
| 1383 | 1437 | |
|---|
| 1384 | | -static bool has_bh_in_lru(int cpu, void *dummy) |
|---|
| 1438 | +bool has_bh_in_lru(int cpu, void *dummy) |
|---|
| 1385 | 1439 | { |
|---|
| 1386 | 1440 | struct bh_lru *b = per_cpu_ptr(&bh_lrus, cpu); |
|---|
| 1387 | 1441 | int i; |
|---|
| 1388 | 1442 | |
|---|
| 1389 | 1443 | for (i = 0; i < BH_LRU_SIZE; i++) { |
|---|
| 1390 | 1444 | if (b->bhs[i]) |
|---|
| 1391 | | - return 1; |
|---|
| 1445 | + return true; |
|---|
| 1392 | 1446 | } |
|---|
| 1393 | 1447 | |
|---|
| 1394 | | - return 0; |
|---|
| 1448 | + return false; |
|---|
| 1395 | 1449 | } |
|---|
| 1396 | 1450 | |
|---|
| 1397 | 1451 | void invalidate_bh_lrus(void) |
|---|
| 1398 | 1452 | { |
|---|
| 1399 | | - on_each_cpu_cond(has_bh_in_lru, invalidate_bh_lru, NULL, 1, GFP_KERNEL); |
|---|
| 1453 | + on_each_cpu_cond(has_bh_in_lru, invalidate_bh_lru, NULL, 1); |
|---|
| 1400 | 1454 | } |
|---|
| 1401 | 1455 | EXPORT_SYMBOL_GPL(invalidate_bh_lrus); |
|---|
| 1456 | + |
|---|
| 1457 | +/* |
|---|
| 1458 | + * It's called from workqueue context so we need a bh_lru_lock to close |
|---|
| 1459 | + * the race with preemption/irq. |
|---|
| 1460 | + */ |
|---|
| 1461 | +void invalidate_bh_lrus_cpu(void) |
|---|
| 1462 | +{ |
|---|
| 1463 | + struct bh_lru *b; |
|---|
| 1464 | + |
|---|
| 1465 | + bh_lru_lock(); |
|---|
| 1466 | + b = this_cpu_ptr(&bh_lrus); |
|---|
| 1467 | + __invalidate_bh_lrus(b); |
|---|
| 1468 | + bh_lru_unlock(); |
|---|
| 1469 | +} |
|---|
| 1402 | 1470 | |
|---|
| 1403 | 1471 | void set_bh_page(struct buffer_head *bh, |
|---|
| 1404 | 1472 | struct page *page, unsigned long offset) |
|---|
| .. | .. |
|---|
| 1505 | 1573 | out: |
|---|
| 1506 | 1574 | return; |
|---|
| 1507 | 1575 | } |
|---|
| 1508 | | -EXPORT_SYMBOL(block_invalidatepage); |
|---|
| 1576 | +EXPORT_SYMBOL_NS(block_invalidatepage, ANDROID_GKI_VFS_EXPORT_ONLY); |
|---|
| 1509 | 1577 | |
|---|
| 1510 | 1578 | |
|---|
| 1511 | 1579 | /* |
|---|
| .. | .. |
|---|
| 1538 | 1606 | bh = bh->b_this_page; |
|---|
| 1539 | 1607 | } while (bh != head); |
|---|
| 1540 | 1608 | } |
|---|
| 1541 | | - attach_page_buffers(page, head); |
|---|
| 1609 | + attach_page_private(page, head); |
|---|
| 1542 | 1610 | spin_unlock(&page->mapping->private_lock); |
|---|
| 1543 | 1611 | } |
|---|
| 1544 | | -EXPORT_SYMBOL(create_empty_buffers); |
|---|
| 1612 | +EXPORT_SYMBOL_NS(create_empty_buffers, ANDROID_GKI_VFS_EXPORT_ONLY); |
|---|
| 1545 | 1613 | |
|---|
| 1546 | 1614 | /** |
|---|
| 1547 | 1615 | * clean_bdev_aliases: clean a range of buffers in block device |
|---|
| .. | .. |
|---|
| 1615 | 1683 | break; |
|---|
| 1616 | 1684 | } |
|---|
| 1617 | 1685 | } |
|---|
| 1618 | | -EXPORT_SYMBOL(clean_bdev_aliases); |
|---|
| 1686 | +EXPORT_SYMBOL_NS(clean_bdev_aliases, ANDROID_GKI_VFS_EXPORT_ONLY); |
|---|
| 1619 | 1687 | |
|---|
| 1620 | 1688 | /* |
|---|
| 1621 | 1689 | * Size is a power-of-two in the range 512..PAGE_SIZE, |
|---|
| .. | .. |
|---|
| 1873 | 1941 | bh = bh->b_this_page; |
|---|
| 1874 | 1942 | } while (bh != head); |
|---|
| 1875 | 1943 | } |
|---|
| 1876 | | -EXPORT_SYMBOL(page_zero_new_buffers); |
|---|
| 1944 | +EXPORT_SYMBOL_NS(page_zero_new_buffers, ANDROID_GKI_VFS_EXPORT_ONLY); |
|---|
| 1877 | 1945 | |
|---|
| 1878 | 1946 | static void |
|---|
| 1879 | 1947 | iomap_to_bh(struct inode *inode, sector_t block, struct buffer_head *bh, |
|---|
| .. | .. |
|---|
| 1918 | 1986 | */ |
|---|
| 1919 | 1987 | set_buffer_new(bh); |
|---|
| 1920 | 1988 | set_buffer_unwritten(bh); |
|---|
| 1921 | | - /* FALLTHRU */ |
|---|
| 1989 | + fallthrough; |
|---|
| 1922 | 1990 | case IOMAP_MAPPED: |
|---|
| 1923 | 1991 | if ((iomap->flags & IOMAP_F_NEW) || |
|---|
| 1924 | 1992 | offset >= i_size_read(inode)) |
|---|
| .. | .. |
|---|
| 2089 | 2157 | } |
|---|
| 2090 | 2158 | EXPORT_SYMBOL(block_write_begin); |
|---|
| 2091 | 2159 | |
|---|
| 2092 | | -int __generic_write_end(struct inode *inode, loff_t pos, unsigned copied, |
|---|
| 2093 | | - struct page *page) |
|---|
| 2094 | | -{ |
|---|
| 2095 | | - loff_t old_size = inode->i_size; |
|---|
| 2096 | | - bool i_size_changed = false; |
|---|
| 2097 | | - |
|---|
| 2098 | | - /* |
|---|
| 2099 | | - * No need to use i_size_read() here, the i_size cannot change under us |
|---|
| 2100 | | - * because we hold i_rwsem. |
|---|
| 2101 | | - * |
|---|
| 2102 | | - * But it's important to update i_size while still holding page lock: |
|---|
| 2103 | | - * page writeout could otherwise come in and zero beyond i_size. |
|---|
| 2104 | | - */ |
|---|
| 2105 | | - if (pos + copied > inode->i_size) { |
|---|
| 2106 | | - i_size_write(inode, pos + copied); |
|---|
| 2107 | | - i_size_changed = true; |
|---|
| 2108 | | - } |
|---|
| 2109 | | - |
|---|
| 2110 | | - unlock_page(page); |
|---|
| 2111 | | - put_page(page); |
|---|
| 2112 | | - |
|---|
| 2113 | | - if (old_size < pos) |
|---|
| 2114 | | - pagecache_isize_extended(inode, old_size, pos); |
|---|
| 2115 | | - /* |
|---|
| 2116 | | - * Don't mark the inode dirty under page lock. First, it unnecessarily |
|---|
| 2117 | | - * makes the holding time of page lock longer. Second, it forces lock |
|---|
| 2118 | | - * ordering of page lock and transaction start for journaling |
|---|
| 2119 | | - * filesystems. |
|---|
| 2120 | | - */ |
|---|
| 2121 | | - if (i_size_changed) |
|---|
| 2122 | | - mark_inode_dirty(inode); |
|---|
| 2123 | | - return copied; |
|---|
| 2124 | | -} |
|---|
| 2125 | | - |
|---|
| 2126 | 2160 | int block_write_end(struct file *file, struct address_space *mapping, |
|---|
| 2127 | 2161 | loff_t pos, unsigned len, unsigned copied, |
|---|
| 2128 | 2162 | struct page *page, void *fsdata) |
|---|
| .. | .. |
|---|
| 2163 | 2197 | loff_t pos, unsigned len, unsigned copied, |
|---|
| 2164 | 2198 | struct page *page, void *fsdata) |
|---|
| 2165 | 2199 | { |
|---|
| 2200 | + struct inode *inode = mapping->host; |
|---|
| 2201 | + loff_t old_size = inode->i_size; |
|---|
| 2202 | + bool i_size_changed = false; |
|---|
| 2203 | + |
|---|
| 2166 | 2204 | copied = block_write_end(file, mapping, pos, len, copied, page, fsdata); |
|---|
| 2167 | | - return __generic_write_end(mapping->host, pos, copied, page); |
|---|
| 2205 | + |
|---|
| 2206 | + /* |
|---|
| 2207 | + * No need to use i_size_read() here, the i_size cannot change under us |
|---|
| 2208 | + * because we hold i_rwsem. |
|---|
| 2209 | + * |
|---|
| 2210 | + * But it's important to update i_size while still holding page lock: |
|---|
| 2211 | + * page writeout could otherwise come in and zero beyond i_size. |
|---|
| 2212 | + */ |
|---|
| 2213 | + if (pos + copied > inode->i_size) { |
|---|
| 2214 | + i_size_write(inode, pos + copied); |
|---|
| 2215 | + i_size_changed = true; |
|---|
| 2216 | + } |
|---|
| 2217 | + |
|---|
| 2218 | + unlock_page(page); |
|---|
| 2219 | + put_page(page); |
|---|
| 2220 | + |
|---|
| 2221 | + if (old_size < pos) |
|---|
| 2222 | + pagecache_isize_extended(inode, old_size, pos); |
|---|
| 2223 | + /* |
|---|
| 2224 | + * Don't mark the inode dirty under page lock. First, it unnecessarily |
|---|
| 2225 | + * makes the holding time of page lock longer. Second, it forces lock |
|---|
| 2226 | + * ordering of page lock and transaction start for journaling |
|---|
| 2227 | + * filesystems. |
|---|
| 2228 | + */ |
|---|
| 2229 | + if (i_size_changed) |
|---|
| 2230 | + mark_inode_dirty(inode); |
|---|
| 2231 | + return copied; |
|---|
| 2168 | 2232 | } |
|---|
| 2169 | 2233 | EXPORT_SYMBOL(generic_write_end); |
|---|
| 2170 | 2234 | |
|---|
| .. | .. |
|---|
| 2211 | 2275 | |
|---|
| 2212 | 2276 | return ret; |
|---|
| 2213 | 2277 | } |
|---|
| 2214 | | -EXPORT_SYMBOL(block_is_partially_uptodate); |
|---|
| 2278 | +EXPORT_SYMBOL_NS(block_is_partially_uptodate, ANDROID_GKI_VFS_EXPORT_ONLY); |
|---|
| 2215 | 2279 | |
|---|
| 2216 | 2280 | /* |
|---|
| 2217 | 2281 | * Generic "read page" function for block devices that have the normal |
|---|
| .. | .. |
|---|
| 2314 | 2378 | { |
|---|
| 2315 | 2379 | struct address_space *mapping = inode->i_mapping; |
|---|
| 2316 | 2380 | struct page *page; |
|---|
| 2317 | | - void *fsdata; |
|---|
| 2381 | + void *fsdata = NULL; |
|---|
| 2318 | 2382 | int err; |
|---|
| 2319 | 2383 | |
|---|
| 2320 | 2384 | err = inode_newsize_ok(inode, size); |
|---|
| .. | .. |
|---|
| 2340 | 2404 | struct inode *inode = mapping->host; |
|---|
| 2341 | 2405 | unsigned int blocksize = i_blocksize(inode); |
|---|
| 2342 | 2406 | struct page *page; |
|---|
| 2343 | | - void *fsdata; |
|---|
| 2407 | + void *fsdata = NULL; |
|---|
| 2344 | 2408 | pgoff_t index, curidx; |
|---|
| 2345 | 2409 | loff_t curpos; |
|---|
| 2346 | 2410 | unsigned zerofrom, offset, len; |
|---|
| .. | .. |
|---|
| 2371 | 2435 | |
|---|
| 2372 | 2436 | balance_dirty_pages_ratelimited(mapping); |
|---|
| 2373 | 2437 | |
|---|
| 2374 | | - if (unlikely(fatal_signal_pending(current))) { |
|---|
| 2438 | + if (fatal_signal_pending(current)) { |
|---|
| 2375 | 2439 | err = -EINTR; |
|---|
| 2376 | 2440 | goto out; |
|---|
| 2377 | 2441 | } |
|---|
| .. | .. |
|---|
| 2529 | 2593 | bh->b_this_page = head; |
|---|
| 2530 | 2594 | bh = bh->b_this_page; |
|---|
| 2531 | 2595 | } while (bh != head); |
|---|
| 2532 | | - attach_page_buffers(page, head); |
|---|
| 2596 | + attach_page_private(page, head); |
|---|
| 2533 | 2597 | spin_unlock(&page->mapping->private_lock); |
|---|
| 2534 | 2598 | } |
|---|
| 2535 | 2599 | |
|---|
| .. | .. |
|---|
| 2970 | 3034 | bio_put(bio); |
|---|
| 2971 | 3035 | } |
|---|
| 2972 | 3036 | |
|---|
| 2973 | | -/* |
|---|
| 2974 | | - * This allows us to do IO even on the odd last sectors |
|---|
| 2975 | | - * of a device, even if the block size is some multiple |
|---|
| 2976 | | - * of the physical sector size. |
|---|
| 2977 | | - * |
|---|
| 2978 | | - * We'll just truncate the bio to the size of the device, |
|---|
| 2979 | | - * and clear the end of the buffer head manually. |
|---|
| 2980 | | - * |
|---|
| 2981 | | - * Truly out-of-range accesses will turn into actual IO |
|---|
| 2982 | | - * errors, this only handles the "we need to be able to |
|---|
| 2983 | | - * do IO at the final sector" case. |
|---|
| 2984 | | - */ |
|---|
| 2985 | | -void guard_bio_eod(int op, struct bio *bio) |
|---|
| 2986 | | -{ |
|---|
| 2987 | | - sector_t maxsector; |
|---|
| 2988 | | - struct bio_vec *bvec = bio_last_bvec_all(bio); |
|---|
| 2989 | | - unsigned truncated_bytes; |
|---|
| 2990 | | - struct hd_struct *part; |
|---|
| 2991 | | - |
|---|
| 2992 | | - rcu_read_lock(); |
|---|
| 2993 | | - part = __disk_get_part(bio->bi_disk, bio->bi_partno); |
|---|
| 2994 | | - if (part) |
|---|
| 2995 | | - maxsector = part_nr_sects_read(part); |
|---|
| 2996 | | - else |
|---|
| 2997 | | - maxsector = get_capacity(bio->bi_disk); |
|---|
| 2998 | | - rcu_read_unlock(); |
|---|
| 2999 | | - |
|---|
| 3000 | | - if (!maxsector) |
|---|
| 3001 | | - return; |
|---|
| 3002 | | - |
|---|
| 3003 | | - /* |
|---|
| 3004 | | - * If the *whole* IO is past the end of the device, |
|---|
| 3005 | | - * let it through, and the IO layer will turn it into |
|---|
| 3006 | | - * an EIO. |
|---|
| 3007 | | - */ |
|---|
| 3008 | | - if (unlikely(bio->bi_iter.bi_sector >= maxsector)) |
|---|
| 3009 | | - return; |
|---|
| 3010 | | - |
|---|
| 3011 | | - maxsector -= bio->bi_iter.bi_sector; |
|---|
| 3012 | | - if (likely((bio->bi_iter.bi_size >> 9) <= maxsector)) |
|---|
| 3013 | | - return; |
|---|
| 3014 | | - |
|---|
| 3015 | | - /* Uhhuh. We've got a bio that straddles the device size! */ |
|---|
| 3016 | | - truncated_bytes = bio->bi_iter.bi_size - (maxsector << 9); |
|---|
| 3017 | | - |
|---|
| 3018 | | - /* |
|---|
| 3019 | | - * The bio contains more than one segment which spans EOD, just return |
|---|
| 3020 | | - * and let IO layer turn it into an EIO |
|---|
| 3021 | | - */ |
|---|
| 3022 | | - if (truncated_bytes > bvec->bv_len) |
|---|
| 3023 | | - return; |
|---|
| 3024 | | - |
|---|
| 3025 | | - /* Truncate the bio.. */ |
|---|
| 3026 | | - bio->bi_iter.bi_size -= truncated_bytes; |
|---|
| 3027 | | - bvec->bv_len -= truncated_bytes; |
|---|
| 3028 | | - |
|---|
| 3029 | | - /* ..and clear the end of the buffer for reads */ |
|---|
| 3030 | | - if (op == REQ_OP_READ) { |
|---|
| 3031 | | - zero_user(bvec->bv_page, bvec->bv_offset + bvec->bv_len, |
|---|
| 3032 | | - truncated_bytes); |
|---|
| 3033 | | - } |
|---|
| 3034 | | -} |
|---|
| 3035 | | - |
|---|
| 3036 | 3037 | static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh, |
|---|
| 3037 | 3038 | enum rw_hint write_hint, struct writeback_control *wbc) |
|---|
| 3038 | 3039 | { |
|---|
| .. | .. |
|---|
| 3050 | 3051 | if (test_set_buffer_req(bh) && (op == REQ_OP_WRITE)) |
|---|
| 3051 | 3052 | clear_buffer_write_io_error(bh); |
|---|
| 3052 | 3053 | |
|---|
| 3053 | | - /* |
|---|
| 3054 | | - * from here on down, it's all bio -- do the initial mapping, |
|---|
| 3055 | | - * submit_bio -> generic_make_request may further map this bio around |
|---|
| 3056 | | - */ |
|---|
| 3057 | 3054 | bio = bio_alloc(GFP_NOIO, 1); |
|---|
| 3058 | 3055 | |
|---|
| 3059 | 3056 | fscrypt_set_bio_crypt_ctx_bh(bio, bh, GFP_NOIO); |
|---|
| 3060 | | - |
|---|
| 3061 | | - if (wbc) { |
|---|
| 3062 | | - wbc_init_bio(wbc, bio); |
|---|
| 3063 | | - wbc_account_io(wbc, bh->b_page, bh->b_size); |
|---|
| 3064 | | - } |
|---|
| 3065 | 3057 | |
|---|
| 3066 | 3058 | bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9); |
|---|
| 3067 | 3059 | bio_set_dev(bio, bh->b_bdev); |
|---|
| .. | .. |
|---|
| 3073 | 3065 | bio->bi_end_io = end_bio_bh_io_sync; |
|---|
| 3074 | 3066 | bio->bi_private = bh; |
|---|
| 3075 | 3067 | |
|---|
| 3076 | | - /* Take care of bh's that straddle the end of the device */ |
|---|
| 3077 | | - guard_bio_eod(op, bio); |
|---|
| 3078 | | - |
|---|
| 3079 | 3068 | if (buffer_meta(bh)) |
|---|
| 3080 | 3069 | op_flags |= REQ_META; |
|---|
| 3081 | 3070 | if (buffer_prio(bh)) |
|---|
| 3082 | 3071 | op_flags |= REQ_PRIO; |
|---|
| 3083 | 3072 | bio_set_op_attrs(bio, op, op_flags); |
|---|
| 3073 | + |
|---|
| 3074 | + /* Take care of bh's that straddle the end of the device */ |
|---|
| 3075 | + guard_bio_eod(bio); |
|---|
| 3076 | + |
|---|
| 3077 | + if (wbc) { |
|---|
| 3078 | + wbc_init_bio(wbc, bio); |
|---|
| 3079 | + wbc_account_cgroup_owner(wbc, bh->b_page, bh->b_size); |
|---|
| 3080 | + } |
|---|
| 3084 | 3081 | |
|---|
| 3085 | 3082 | submit_bio(bio); |
|---|
| 3086 | 3083 | return 0; |
|---|
| .. | .. |
|---|
| 3145 | 3142 | unlock_buffer(bh); |
|---|
| 3146 | 3143 | } |
|---|
| 3147 | 3144 | } |
|---|
| 3148 | | -EXPORT_SYMBOL(ll_rw_block); |
|---|
| 3145 | +EXPORT_SYMBOL_NS(ll_rw_block, ANDROID_GKI_VFS_EXPORT_ONLY); |
|---|
| 3149 | 3146 | |
|---|
| 3150 | 3147 | void write_dirty_buffer(struct buffer_head *bh, int op_flags) |
|---|
| 3151 | 3148 | { |
|---|
| .. | .. |
|---|
| 3198 | 3195 | { |
|---|
| 3199 | 3196 | return __sync_dirty_buffer(bh, REQ_SYNC); |
|---|
| 3200 | 3197 | } |
|---|
| 3201 | | -EXPORT_SYMBOL(sync_dirty_buffer); |
|---|
| 3198 | +EXPORT_SYMBOL_NS(sync_dirty_buffer, ANDROID_GKI_VFS_EXPORT_ONLY); |
|---|
| 3202 | 3199 | |
|---|
| 3203 | 3200 | /* |
|---|
| 3204 | 3201 | * try_to_free_buffers() checks if all the buffers on this particular page |
|---|
| .. | .. |
|---|
| 3247 | 3244 | bh = next; |
|---|
| 3248 | 3245 | } while (bh != head); |
|---|
| 3249 | 3246 | *buffers_to_free = head; |
|---|
| 3250 | | - __clear_page_buffers(page); |
|---|
| 3247 | + detach_page_private(page); |
|---|
| 3251 | 3248 | return 1; |
|---|
| 3252 | 3249 | failed: |
|---|
| 3253 | 3250 | return 0; |
|---|
| .. | .. |
|---|
| 3367 | 3364 | struct buffer_head *ret = kmem_cache_zalloc(bh_cachep, gfp_flags); |
|---|
| 3368 | 3365 | if (ret) { |
|---|
| 3369 | 3366 | INIT_LIST_HEAD(&ret->b_assoc_buffers); |
|---|
| 3370 | | - buffer_head_init_locks(ret); |
|---|
| 3367 | + spin_lock_init(&ret->b_uptodate_lock); |
|---|
| 3371 | 3368 | preempt_disable(); |
|---|
| 3372 | 3369 | __this_cpu_inc(bh_accounting.nr); |
|---|
| 3373 | 3370 | recalc_bh_state(); |
|---|