hc
2024-05-10 10ebd8556b7990499c896a550e3d416b444211e6
kernel/fs/buffer.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/fs/buffer.c
34 *
....@@ -47,6 +48,8 @@
4748 #include <linux/sched/mm.h>
4849 #include <trace/events/block.h>
4950 #include <linux/fscrypt.h>
51
+
52
+#include "internal.h"
5053
5154 static int fsync_buffers_list(spinlock_t *lock, struct list_head *list);
5255 static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh,
....@@ -120,14 +123,6 @@
120123 }
121124 EXPORT_SYMBOL(__wait_on_buffer);
122125
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
-
131126 static void buffer_io_error(struct buffer_head *bh, char *msg)
132127 {
133128 if (!test_bit(BH_Quiet, &bh->b_state))
....@@ -178,7 +173,7 @@
178173 unlock_buffer(bh);
179174 put_bh(bh);
180175 }
181
-EXPORT_SYMBOL(end_buffer_write_sync);
176
+EXPORT_SYMBOL_NS(end_buffer_write_sync, ANDROID_GKI_VFS_EXPORT_ONLY);
182177
183178 /*
184179 * Various filesystems appear to want __find_get_block to be non-blocking.
....@@ -246,10 +241,6 @@
246241 return ret;
247242 }
248243
249
-/*
250
- * I/O completion handler for block_read_full_page() - pages
251
- * which come unlocked at the end of I/O.
252
- */
253244 static void end_buffer_async_read(struct buffer_head *bh, int uptodate)
254245 {
255246 unsigned long flags;
....@@ -275,8 +266,7 @@
275266 * decide that the page is now completely done.
276267 */
277268 first = page_buffers(page);
278
- local_irq_save(flags);
279
- bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
269
+ spin_lock_irqsave(&first->b_uptodate_lock, flags);
280270 clear_buffer_async_read(bh);
281271 unlock_buffer(bh);
282272 tmp = bh;
....@@ -289,8 +279,7 @@
289279 }
290280 tmp = tmp->b_this_page;
291281 } while (tmp != bh);
292
- bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
293
- local_irq_restore(flags);
282
+ spin_unlock_irqrestore(&first->b_uptodate_lock, flags);
294283
295284 /*
296285 * If none of the buffers had errors and they are all
....@@ -302,9 +291,48 @@
302291 return;
303292
304293 still_busy:
305
- bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
306
- local_irq_restore(flags);
294
+ spin_unlock_irqrestore(&first->b_uptodate_lock, flags);
307295 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);
308336 }
309337
310338 /*
....@@ -331,8 +359,7 @@
331359 }
332360
333361 first = page_buffers(page);
334
- local_irq_save(flags);
335
- bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
362
+ spin_lock_irqsave(&first->b_uptodate_lock, flags);
336363
337364 clear_buffer_async_write(bh);
338365 unlock_buffer(bh);
....@@ -344,14 +371,12 @@
344371 }
345372 tmp = tmp->b_this_page;
346373 }
347
- bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
348
- local_irq_restore(flags);
374
+ spin_unlock_irqrestore(&first->b_uptodate_lock, flags);
349375 end_page_writeback(page);
350376 return;
351377
352378 still_busy:
353
- bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
354
- local_irq_restore(flags);
379
+ spin_unlock_irqrestore(&first->b_uptodate_lock, flags);
355380 return;
356381 }
357382 EXPORT_SYMBOL(end_buffer_async_write);
....@@ -379,7 +404,7 @@
379404 */
380405 static void mark_buffer_async_read(struct buffer_head *bh)
381406 {
382
- bh->b_end_io = end_buffer_async_read;
407
+ bh->b_end_io = end_buffer_async_read_io;
383408 set_buffer_async_read(bh);
384409 }
385410
....@@ -394,7 +419,7 @@
394419 {
395420 mark_buffer_async_write_endio(bh, end_buffer_async_write);
396421 }
397
-EXPORT_SYMBOL(mark_buffer_async_write);
422
+EXPORT_SYMBOL_NS(mark_buffer_async_write, ANDROID_GKI_VFS_EXPORT_ONLY);
398423
399424
400425 /*
....@@ -498,7 +523,7 @@
498523
499524 void emergency_thaw_bdev(struct super_block *sb)
500525 {
501
- while (sb->s_bdev && !thaw_bdev(sb->s_bdev, sb))
526
+ while (sb->s_bdev && !thaw_bdev(sb->s_bdev))
502527 printk(KERN_WARNING "Emergency Thaw on %pg\n", sb->s_bdev);
503528 }
504529
....@@ -564,7 +589,7 @@
564589 EXPORT_SYMBOL(mark_buffer_dirty_inode);
565590
566591 /*
567
- * 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
568593 * dirty.
569594 *
570595 * If warn is true, then emit a warning if the page is not uptodate and has
....@@ -581,8 +606,8 @@
581606 if (page->mapping) { /* Race with truncate? */
582607 WARN_ON_ONCE(warn && !PageUptodate(page));
583608 account_page_dirtied(page, mapping);
584
- radix_tree_tag_set(&mapping->i_pages,
585
- page_index(page), PAGECACHE_TAG_DIRTY);
609
+ __xa_set_mark(&mapping->i_pages, page_index(page),
610
+ PAGECACHE_TAG_DIRTY);
586611 }
587612 xa_unlock_irqrestore(&mapping->i_pages, flags);
588613 }
....@@ -649,7 +674,7 @@
649674
650675 return newly_dirty;
651676 }
652
-EXPORT_SYMBOL(__set_page_dirty_buffers);
677
+EXPORT_SYMBOL_NS(__set_page_dirty_buffers, ANDROID_GKI_VFS_EXPORT_ONLY);
653678
654679 /*
655680 * Write out and wait upon a list of buffers.
....@@ -817,13 +842,13 @@
817842 struct buffer_head *bh, *head;
818843 gfp_t gfp = GFP_NOFS | __GFP_ACCOUNT;
819844 long offset;
820
- struct mem_cgroup *memcg;
845
+ struct mem_cgroup *memcg, *old_memcg;
821846
822847 if (retry)
823848 gfp |= __GFP_NOFAIL;
824849
825850 memcg = get_mem_cgroup_from_page(page);
826
- memalloc_use_memcg(memcg);
851
+ old_memcg = set_active_memcg(memcg);
827852
828853 head = NULL;
829854 offset = PAGE_SIZE;
....@@ -842,7 +867,7 @@
842867 set_bh_page(bh, page, offset);
843868 }
844869 out:
845
- memalloc_unuse_memcg();
870
+ set_active_memcg(old_memcg);
846871 mem_cgroup_put(memcg);
847872 return head;
848873 /*
....@@ -872,7 +897,7 @@
872897 bh = bh->b_this_page;
873898 } while (bh);
874899 tail->b_this_page = head;
875
- attach_page_buffers(page, head);
900
+ attach_page_private(page, head);
876901 }
877902
878903 static sector_t blkdev_max_block(struct block_device *bdev, unsigned int size)
....@@ -933,7 +958,7 @@
933958 struct page *page;
934959 struct buffer_head *bh;
935960 sector_t end_block;
936
- int ret = 0; /* Will call free_more_memory() */
961
+ int ret = 0;
937962 gfp_t gfp_mask;
938963
939964 gfp_mask = mapping_gfp_constraint(inode->i_mapping, ~__GFP_FS) | gfp;
....@@ -1052,7 +1077,7 @@
10521077 * The relationship between dirty buffers and dirty pages:
10531078 *
10541079 * Whenever a page has any dirty buffers, the page's dirty bit is set, and
1055
- * the page is tagged dirty in its radix tree.
1080
+ * the page is tagged dirty in the page cache.
10561081 *
10571082 * At all times, the dirtiness of the buffers represents the dirtiness of
10581083 * subsections of the page. If the page has buffers, the page dirty bit is
....@@ -1075,9 +1100,9 @@
10751100 * mark_buffer_dirty - mark a buffer_head as needing writeout
10761101 * @bh: the buffer_head to mark dirty
10771102 *
1078
- * mark_buffer_dirty() will set the dirty bit against the buffer, then set its
1079
- * backing page dirty, then tag the page as dirty in its address_space's radix
1080
- * 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
10811106 * inode list.
10821107 *
10831108 * mark_buffer_dirty() is atomic. It takes bh->b_page->mapping->private_lock,
....@@ -1116,18 +1141,25 @@
11161141 __mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
11171142 }
11181143 }
1119
-EXPORT_SYMBOL(mark_buffer_dirty);
1144
+EXPORT_SYMBOL_NS(mark_buffer_dirty, ANDROID_GKI_VFS_EXPORT_ONLY);
11201145
11211146 void mark_buffer_write_io_error(struct buffer_head *bh)
11221147 {
1148
+ struct super_block *sb;
1149
+
11231150 set_buffer_write_io_error(bh);
11241151 /* FIXME: do we need to set this in both places? */
11251152 if (bh->b_page && bh->b_page->mapping)
11261153 mapping_set_error(bh->b_page->mapping, -EIO);
11271154 if (bh->b_assoc_map)
11281155 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();
11291161 }
1130
-EXPORT_SYMBOL(mark_buffer_write_io_error);
1162
+EXPORT_SYMBOL_NS(mark_buffer_write_io_error, ANDROID_GKI_VFS_EXPORT_ONLY);
11311163
11321164 /*
11331165 * Decrement a buffer_head's reference count. If all buffers against a page
....@@ -1144,7 +1176,7 @@
11441176 }
11451177 WARN(1, KERN_ERR "VFS: brelse: Trying to free free buffer\n");
11461178 }
1147
-EXPORT_SYMBOL(__brelse);
1179
+EXPORT_SYMBOL_NS(__brelse, ANDROID_GKI_VFS_EXPORT_ONLY);
11481180
11491181 /*
11501182 * bforget() is like brelse(), except it discards any
....@@ -1163,7 +1195,7 @@
11631195 }
11641196 __brelse(bh);
11651197 }
1166
-EXPORT_SYMBOL(__bforget);
1198
+EXPORT_SYMBOL_NS(__bforget, ANDROID_GKI_VFS_EXPORT_ONLY);
11671199
11681200 static struct buffer_head *__bread_slow(struct buffer_head *bh)
11691201 {
....@@ -1232,6 +1264,15 @@
12321264 int i;
12331265
12341266 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
+
12351276 bh_lru_lock();
12361277
12371278 b = this_cpu_ptr(&bh_lrus);
....@@ -1335,7 +1376,7 @@
13351376 brelse(bh);
13361377 }
13371378 }
1338
-EXPORT_SYMBOL(__breadahead);
1379
+EXPORT_SYMBOL_NS(__breadahead, ANDROID_GKI_VFS_EXPORT_ONLY);
13391380
13401381 void __breadahead_gfp(struct block_device *bdev, sector_t block, unsigned size,
13411382 gfp_t gfp)
....@@ -1370,8 +1411,17 @@
13701411 bh = __bread_slow(bh);
13711412 return bh;
13721413 }
1373
-EXPORT_SYMBOL(__bread_gfp);
1414
+EXPORT_SYMBOL_NS(__bread_gfp, ANDROID_GKI_VFS_EXPORT_ONLY);
13741415
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
+}
13751425 /*
13761426 * invalidate_bh_lrus() is called rarely - but not only at unmount.
13771427 * This doesn't race because it runs in each cpu either in irq
....@@ -1380,33 +1430,43 @@
13801430 static void invalidate_bh_lru(void *arg)
13811431 {
13821432 struct bh_lru *b = &get_cpu_var(bh_lrus);
1383
- int i;
13841433
1385
- for (i = 0; i < BH_LRU_SIZE; i++) {
1386
- brelse(b->bhs[i]);
1387
- b->bhs[i] = NULL;
1388
- }
1434
+ __invalidate_bh_lrus(b);
13891435 put_cpu_var(bh_lrus);
13901436 }
13911437
1392
-static bool has_bh_in_lru(int cpu, void *dummy)
1438
+bool has_bh_in_lru(int cpu, void *dummy)
13931439 {
13941440 struct bh_lru *b = per_cpu_ptr(&bh_lrus, cpu);
13951441 int i;
13961442
13971443 for (i = 0; i < BH_LRU_SIZE; i++) {
13981444 if (b->bhs[i])
1399
- return 1;
1445
+ return true;
14001446 }
14011447
1402
- return 0;
1448
+ return false;
14031449 }
14041450
14051451 void invalidate_bh_lrus(void)
14061452 {
1407
- 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);
14081454 }
14091455 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
+}
14101470
14111471 void set_bh_page(struct buffer_head *bh,
14121472 struct page *page, unsigned long offset)
....@@ -1513,7 +1573,7 @@
15131573 out:
15141574 return;
15151575 }
1516
-EXPORT_SYMBOL(block_invalidatepage);
1576
+EXPORT_SYMBOL_NS(block_invalidatepage, ANDROID_GKI_VFS_EXPORT_ONLY);
15171577
15181578
15191579 /*
....@@ -1546,10 +1606,10 @@
15461606 bh = bh->b_this_page;
15471607 } while (bh != head);
15481608 }
1549
- attach_page_buffers(page, head);
1609
+ attach_page_private(page, head);
15501610 spin_unlock(&page->mapping->private_lock);
15511611 }
1552
-EXPORT_SYMBOL(create_empty_buffers);
1612
+EXPORT_SYMBOL_NS(create_empty_buffers, ANDROID_GKI_VFS_EXPORT_ONLY);
15531613
15541614 /**
15551615 * clean_bdev_aliases: clean a range of buffers in block device
....@@ -1623,7 +1683,7 @@
16231683 break;
16241684 }
16251685 }
1626
-EXPORT_SYMBOL(clean_bdev_aliases);
1686
+EXPORT_SYMBOL_NS(clean_bdev_aliases, ANDROID_GKI_VFS_EXPORT_ONLY);
16271687
16281688 /*
16291689 * Size is a power-of-two in the range 512..PAGE_SIZE,
....@@ -1881,7 +1941,7 @@
18811941 bh = bh->b_this_page;
18821942 } while (bh != head);
18831943 }
1884
-EXPORT_SYMBOL(page_zero_new_buffers);
1944
+EXPORT_SYMBOL_NS(page_zero_new_buffers, ANDROID_GKI_VFS_EXPORT_ONLY);
18851945
18861946 static void
18871947 iomap_to_bh(struct inode *inode, sector_t block, struct buffer_head *bh,
....@@ -1926,7 +1986,7 @@
19261986 */
19271987 set_buffer_new(bh);
19281988 set_buffer_unwritten(bh);
1929
- /* FALLTHRU */
1989
+ fallthrough;
19301990 case IOMAP_MAPPED:
19311991 if ((iomap->flags & IOMAP_F_NEW) ||
19321992 offset >= i_size_read(inode))
....@@ -2097,40 +2157,6 @@
20972157 }
20982158 EXPORT_SYMBOL(block_write_begin);
20992159
2100
-int __generic_write_end(struct inode *inode, loff_t pos, unsigned copied,
2101
- struct page *page)
2102
-{
2103
- loff_t old_size = inode->i_size;
2104
- bool i_size_changed = false;
2105
-
2106
- /*
2107
- * No need to use i_size_read() here, the i_size cannot change under us
2108
- * because we hold i_rwsem.
2109
- *
2110
- * But it's important to update i_size while still holding page lock:
2111
- * page writeout could otherwise come in and zero beyond i_size.
2112
- */
2113
- if (pos + copied > inode->i_size) {
2114
- i_size_write(inode, pos + copied);
2115
- i_size_changed = true;
2116
- }
2117
-
2118
- unlock_page(page);
2119
- put_page(page);
2120
-
2121
- if (old_size < pos)
2122
- pagecache_isize_extended(inode, old_size, pos);
2123
- /*
2124
- * Don't mark the inode dirty under page lock. First, it unnecessarily
2125
- * makes the holding time of page lock longer. Second, it forces lock
2126
- * ordering of page lock and transaction start for journaling
2127
- * filesystems.
2128
- */
2129
- if (i_size_changed)
2130
- mark_inode_dirty(inode);
2131
- return copied;
2132
-}
2133
-
21342160 int block_write_end(struct file *file, struct address_space *mapping,
21352161 loff_t pos, unsigned len, unsigned copied,
21362162 struct page *page, void *fsdata)
....@@ -2171,8 +2197,38 @@
21712197 loff_t pos, unsigned len, unsigned copied,
21722198 struct page *page, void *fsdata)
21732199 {
2200
+ struct inode *inode = mapping->host;
2201
+ loff_t old_size = inode->i_size;
2202
+ bool i_size_changed = false;
2203
+
21742204 copied = block_write_end(file, mapping, pos, len, copied, page, fsdata);
2175
- 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;
21762232 }
21772233 EXPORT_SYMBOL(generic_write_end);
21782234
....@@ -2219,7 +2275,7 @@
22192275
22202276 return ret;
22212277 }
2222
-EXPORT_SYMBOL(block_is_partially_uptodate);
2278
+EXPORT_SYMBOL_NS(block_is_partially_uptodate, ANDROID_GKI_VFS_EXPORT_ONLY);
22232279
22242280 /*
22252281 * Generic "read page" function for block devices that have the normal
....@@ -2322,7 +2378,7 @@
23222378 {
23232379 struct address_space *mapping = inode->i_mapping;
23242380 struct page *page;
2325
- void *fsdata;
2381
+ void *fsdata = NULL;
23262382 int err;
23272383
23282384 err = inode_newsize_ok(inode, size);
....@@ -2348,7 +2404,7 @@
23482404 struct inode *inode = mapping->host;
23492405 unsigned int blocksize = i_blocksize(inode);
23502406 struct page *page;
2351
- void *fsdata;
2407
+ void *fsdata = NULL;
23522408 pgoff_t index, curidx;
23532409 loff_t curpos;
23542410 unsigned zerofrom, offset, len;
....@@ -2379,7 +2435,7 @@
23792435
23802436 balance_dirty_pages_ratelimited(mapping);
23812437
2382
- if (unlikely(fatal_signal_pending(current))) {
2438
+ if (fatal_signal_pending(current)) {
23832439 err = -EINTR;
23842440 goto out;
23852441 }
....@@ -2537,7 +2593,7 @@
25372593 bh->b_this_page = head;
25382594 bh = bh->b_this_page;
25392595 } while (bh != head);
2540
- attach_page_buffers(page, head);
2596
+ attach_page_private(page, head);
25412597 spin_unlock(&page->mapping->private_lock);
25422598 }
25432599
....@@ -2978,69 +3034,6 @@
29783034 bio_put(bio);
29793035 }
29803036
2981
-/*
2982
- * This allows us to do IO even on the odd last sectors
2983
- * of a device, even if the block size is some multiple
2984
- * of the physical sector size.
2985
- *
2986
- * We'll just truncate the bio to the size of the device,
2987
- * and clear the end of the buffer head manually.
2988
- *
2989
- * Truly out-of-range accesses will turn into actual IO
2990
- * errors, this only handles the "we need to be able to
2991
- * do IO at the final sector" case.
2992
- */
2993
-void guard_bio_eod(int op, struct bio *bio)
2994
-{
2995
- sector_t maxsector;
2996
- struct bio_vec *bvec = bio_last_bvec_all(bio);
2997
- unsigned truncated_bytes;
2998
- struct hd_struct *part;
2999
-
3000
- rcu_read_lock();
3001
- part = __disk_get_part(bio->bi_disk, bio->bi_partno);
3002
- if (part)
3003
- maxsector = part_nr_sects_read(part);
3004
- else
3005
- maxsector = get_capacity(bio->bi_disk);
3006
- rcu_read_unlock();
3007
-
3008
- if (!maxsector)
3009
- return;
3010
-
3011
- /*
3012
- * If the *whole* IO is past the end of the device,
3013
- * let it through, and the IO layer will turn it into
3014
- * an EIO.
3015
- */
3016
- if (unlikely(bio->bi_iter.bi_sector >= maxsector))
3017
- return;
3018
-
3019
- maxsector -= bio->bi_iter.bi_sector;
3020
- if (likely((bio->bi_iter.bi_size >> 9) <= maxsector))
3021
- return;
3022
-
3023
- /* Uhhuh. We've got a bio that straddles the device size! */
3024
- truncated_bytes = bio->bi_iter.bi_size - (maxsector << 9);
3025
-
3026
- /*
3027
- * The bio contains more than one segment which spans EOD, just return
3028
- * and let IO layer turn it into an EIO
3029
- */
3030
- if (truncated_bytes > bvec->bv_len)
3031
- return;
3032
-
3033
- /* Truncate the bio.. */
3034
- bio->bi_iter.bi_size -= truncated_bytes;
3035
- bvec->bv_len -= truncated_bytes;
3036
-
3037
- /* ..and clear the end of the buffer for reads */
3038
- if (op == REQ_OP_READ) {
3039
- zero_user(bvec->bv_page, bvec->bv_offset + bvec->bv_len,
3040
- truncated_bytes);
3041
- }
3042
-}
3043
-
30443037 static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh,
30453038 enum rw_hint write_hint, struct writeback_control *wbc)
30463039 {
....@@ -3058,18 +3051,9 @@
30583051 if (test_set_buffer_req(bh) && (op == REQ_OP_WRITE))
30593052 clear_buffer_write_io_error(bh);
30603053
3061
- /*
3062
- * from here on down, it's all bio -- do the initial mapping,
3063
- * submit_bio -> generic_make_request may further map this bio around
3064
- */
30653054 bio = bio_alloc(GFP_NOIO, 1);
30663055
30673056 fscrypt_set_bio_crypt_ctx_bh(bio, bh, GFP_NOIO);
3068
-
3069
- if (wbc) {
3070
- wbc_init_bio(wbc, bio);
3071
- wbc_account_io(wbc, bh->b_page, bh->b_size);
3072
- }
30733057
30743058 bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9);
30753059 bio_set_dev(bio, bh->b_bdev);
....@@ -3081,14 +3065,19 @@
30813065 bio->bi_end_io = end_bio_bh_io_sync;
30823066 bio->bi_private = bh;
30833067
3084
- /* Take care of bh's that straddle the end of the device */
3085
- guard_bio_eod(op, bio);
3086
-
30873068 if (buffer_meta(bh))
30883069 op_flags |= REQ_META;
30893070 if (buffer_prio(bh))
30903071 op_flags |= REQ_PRIO;
30913072 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
+ }
30923081
30933082 submit_bio(bio);
30943083 return 0;
....@@ -3153,7 +3142,7 @@
31533142 unlock_buffer(bh);
31543143 }
31553144 }
3156
-EXPORT_SYMBOL(ll_rw_block);
3145
+EXPORT_SYMBOL_NS(ll_rw_block, ANDROID_GKI_VFS_EXPORT_ONLY);
31573146
31583147 void write_dirty_buffer(struct buffer_head *bh, int op_flags)
31593148 {
....@@ -3206,7 +3195,7 @@
32063195 {
32073196 return __sync_dirty_buffer(bh, REQ_SYNC);
32083197 }
3209
-EXPORT_SYMBOL(sync_dirty_buffer);
3198
+EXPORT_SYMBOL_NS(sync_dirty_buffer, ANDROID_GKI_VFS_EXPORT_ONLY);
32103199
32113200 /*
32123201 * try_to_free_buffers() checks if all the buffers on this particular page
....@@ -3255,7 +3244,7 @@
32553244 bh = next;
32563245 } while (bh != head);
32573246 *buffers_to_free = head;
3258
- __clear_page_buffers(page);
3247
+ detach_page_private(page);
32593248 return 1;
32603249 failed:
32613250 return 0;
....@@ -3375,6 +3364,7 @@
33753364 struct buffer_head *ret = kmem_cache_zalloc(bh_cachep, gfp_flags);
33763365 if (ret) {
33773366 INIT_LIST_HEAD(&ret->b_assoc_buffers);
3367
+ spin_lock_init(&ret->b_uptodate_lock);
33783368 preempt_disable();
33793369 __this_cpu_inc(bh_accounting.nr);
33803370 recalc_bh_state();