Orange Pi5 kernel

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

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * linux/fs/ext4/readpage.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2002, Linus Torvalds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2015, Google, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * This was originally taken from fs/mpage.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * The ext4_mpage_readpages() function here is intended to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * replace mpage_readahead() in the general case, not just for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * encrypted files.  It has some limitations (see below), where it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * will fall back to read_block_full_page(), but these limitations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * should only be hit when page_size != block_size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * This will allow us to attach a callback function to support ext4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * encryption.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * If anything unusual happens, such as:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * - encountering a page which has buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * - encountering a page which has a non-hole after a hole
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * - encountering a page with non-contiguous blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * then this code just gives up and calls the buffer_head-based read function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * It does handle a page which has holes at the end - that is a common case:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * the end-of-file on blocksize < PAGE_SIZE setups.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/kdev_t.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <linux/bio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <linux/prefetch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include <linux/mpage.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <linux/writeback.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #include <linux/backing-dev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #include <linux/pagevec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #include <linux/cleancache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #include "ext4.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #include <trace/events/android_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define NUM_PREALLOC_POST_READ_CTXS	128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static struct kmem_cache *bio_post_read_ctx_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static mempool_t *bio_post_read_ctx_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) /* postprocessing steps for read bios */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) enum bio_post_read_step {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	STEP_INITIAL = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	STEP_DECRYPT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	STEP_VERITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	STEP_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) struct bio_post_read_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	unsigned int cur_step;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	unsigned int enabled_steps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static void __read_end_io(struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct bio_vec *bv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct bvec_iter_all iter_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	bio_for_each_segment_all(bv, bio, iter_all) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		page = bv->bv_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		/* PG_error was set if any post_read step failed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		if (bio->bi_status || PageError(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			ClearPageUptodate(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			/* will re-read again later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			ClearPageError(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			SetPageUptodate(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (bio->bi_private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		mempool_free(bio->bi_private, bio_post_read_ctx_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	bio_put(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static void bio_post_read_processing(struct bio_post_read_ctx *ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static void decrypt_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	struct bio_post_read_ctx *ctx =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		container_of(work, struct bio_post_read_ctx, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	fscrypt_decrypt_bio(ctx->bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	bio_post_read_processing(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static void verity_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	struct bio_post_read_ctx *ctx =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		container_of(work, struct bio_post_read_ctx, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct bio *bio = ctx->bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	 * fsverity_verify_bio() may call readpages() again, and although verity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	 * will be disabled for that, decryption may still be needed, causing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	 * another bio_post_read_ctx to be allocated.  So to guarantee that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	 * mempool_alloc() never deadlocks we must free the current ctx first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	 * This is safe because verity is the last post-read step.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	BUILD_BUG_ON(STEP_VERITY + 1 != STEP_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	mempool_free(ctx, bio_post_read_ctx_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	bio->bi_private = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	fsverity_verify_bio(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	__read_end_io(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static void bio_post_read_processing(struct bio_post_read_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	 * We use different work queues for decryption and for verity because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	 * verity may require reading metadata pages that need decryption, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	 * we shouldn't recurse to the same workqueue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	switch (++ctx->cur_step) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	case STEP_DECRYPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		if (ctx->enabled_steps & (1 << STEP_DECRYPT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			INIT_WORK(&ctx->work, decrypt_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			fscrypt_enqueue_decrypt_work(&ctx->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		ctx->cur_step++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	case STEP_VERITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		if (ctx->enabled_steps & (1 << STEP_VERITY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			INIT_WORK(&ctx->work, verity_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			fsverity_enqueue_verify_work(&ctx->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		ctx->cur_step++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		__read_end_io(ctx->bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static bool bio_post_read_required(struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	return bio->bi_private && !bio->bi_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) ext4_trace_read_completion(struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	struct page *first_page = bio->bi_io_vec[0].bv_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (first_page != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		trace_android_fs_dataread_end(first_page->mapping->host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 					      page_offset(first_page),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 					      bio->bi_iter.bi_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  * I/O completion handler for multipage BIOs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  * The mpage code never puts partial pages into a BIO (except for end-of-file).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  * If a page does not map to a contiguous run of blocks then it simply falls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * back to block_read_full_page().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  * Why is this?  If a page's completion depends on a number of different BIOs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  * which can complete in any order (or at the same time) then determining the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  * status of that page is hard.  See end_buffer_async_read() for the details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  * There is no point in duplicating all that complexity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static void mpage_end_io(struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	if (trace_android_fs_dataread_start_enabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		ext4_trace_read_completion(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	if (bio_post_read_required(bio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		struct bio_post_read_ctx *ctx = bio->bi_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		ctx->cur_step = STEP_INITIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		bio_post_read_processing(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	__read_end_io(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static inline bool ext4_need_verity(const struct inode *inode, pgoff_t idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	return fsverity_active(inode) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	       idx < DIV_ROUND_UP(inode->i_size, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static void ext4_set_bio_post_read_ctx(struct bio *bio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 				       const struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 				       pgoff_t first_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	unsigned int post_read_steps = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	if (fscrypt_inode_uses_fs_layer_crypto(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		post_read_steps |= 1 << STEP_DECRYPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (ext4_need_verity(inode, first_idx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		post_read_steps |= 1 << STEP_VERITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	if (post_read_steps) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		/* Due to the mempool, this never fails. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		struct bio_post_read_ctx *ctx =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			mempool_alloc(bio_post_read_ctx_pool, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		ctx->bio = bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		ctx->enabled_steps = post_read_steps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		bio->bi_private = ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static inline loff_t ext4_readpage_limit(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (IS_ENABLED(CONFIG_FS_VERITY) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	    (IS_VERITY(inode) || ext4_verity_in_progress(inode)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		return inode->i_sb->s_maxbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	return i_size_read(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) ext4_submit_bio_read(struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	if (trace_android_fs_dataread_start_enabled()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		struct page *first_page = bio->bi_io_vec[0].bv_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		if (first_page != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			char *path, pathbuf[MAX_TRACE_PATHBUF_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 			path = android_fstrace_get_pathname(pathbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 						    MAX_TRACE_PATHBUF_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 						    first_page->mapping->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			trace_android_fs_dataread_start(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 				first_page->mapping->host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 				page_offset(first_page),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 				bio->bi_iter.bi_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 				current->pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 				path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 				current->comm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	submit_bio(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) int ext4_mpage_readpages(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		struct readahead_control *rac, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	struct bio *bio = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	sector_t last_block_in_bio = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	const unsigned blkbits = inode->i_blkbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	const unsigned blocks_per_page = PAGE_SIZE >> blkbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	const unsigned blocksize = 1 << blkbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	sector_t next_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	sector_t block_in_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	sector_t last_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	sector_t last_block_in_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	sector_t blocks[MAX_BUF_PER_PAGE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	unsigned page_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	struct block_device *bdev = inode->i_sb->s_bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	int length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	unsigned relative_block = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	struct ext4_map_blocks map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	unsigned int nr_pages = rac ? readahead_count(rac) : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	map.m_pblk = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	map.m_lblk = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	map.m_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	map.m_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	for (; nr_pages; nr_pages--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		int fully_mapped = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		unsigned first_hole = blocks_per_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		if (rac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			page = readahead_page(rac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			prefetchw(&page->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		if (page_has_buffers(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			goto confused;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		block_in_file = next_block =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			(sector_t)page->index << (PAGE_SHIFT - blkbits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		last_block = block_in_file + nr_pages * blocks_per_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		last_block_in_file = (ext4_readpage_limit(inode) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 				      blocksize - 1) >> blkbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		if (last_block > last_block_in_file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 			last_block = last_block_in_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		page_block = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		 * Map blocks using the previous result first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		if ((map.m_flags & EXT4_MAP_MAPPED) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		    block_in_file > map.m_lblk &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		    block_in_file < (map.m_lblk + map.m_len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 			unsigned map_offset = block_in_file - map.m_lblk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 			unsigned last = map.m_len - map_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 			for (relative_block = 0; ; relative_block++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 				if (relative_block == last) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 					/* needed? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 					map.m_flags &= ~EXT4_MAP_MAPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 				if (page_block == blocks_per_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 				blocks[page_block] = map.m_pblk + map_offset +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 					relative_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 				page_block++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 				block_in_file++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		 * Then do more ext4_map_blocks() calls until we are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		 * done with this page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		while (page_block < blocks_per_page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 			if (block_in_file < last_block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 				map.m_lblk = block_in_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 				map.m_len = last_block - block_in_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 				if (ext4_map_blocks(NULL, inode, &map, 0) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 				set_error_page:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 					SetPageError(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 					zero_user_segment(page, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 							  PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 					unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 					goto next_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			if ((map.m_flags & EXT4_MAP_MAPPED) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 				fully_mapped = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 				if (first_hole == blocks_per_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 					first_hole = page_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 				page_block++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 				block_in_file++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			if (first_hole != blocks_per_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 				goto confused;		/* hole -> non-hole */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 			/* Contiguous blocks? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 			if (page_block && blocks[page_block-1] != map.m_pblk-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 				goto confused;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 			for (relative_block = 0; ; relative_block++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 				if (relative_block == map.m_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 					/* needed? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 					map.m_flags &= ~EXT4_MAP_MAPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 				} else if (page_block == blocks_per_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 				blocks[page_block] = map.m_pblk+relative_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 				page_block++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 				block_in_file++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		if (first_hole != blocks_per_page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 			zero_user_segment(page, first_hole << blkbits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 					  PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 			if (first_hole == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 				if (ext4_need_verity(inode, page->index) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 				    !fsverity_verify_page(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 					goto set_error_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 				SetPageUptodate(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 				unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 				goto next_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		} else if (fully_mapped) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 			SetPageMappedToDisk(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		if (fully_mapped && blocks_per_page == 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		    !PageUptodate(page) && cleancache_get_page(page) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 			SetPageUptodate(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 			goto confused;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		 * This page will go to BIO.  Do we need to send this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		 * BIO off first?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		if (bio && (last_block_in_bio != blocks[0] - 1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 			    !fscrypt_mergeable_bio(bio, inode, next_block))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		submit_and_realloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 			ext4_submit_bio_read(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 			bio = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		if (bio == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 			 * bio_alloc will _always_ be able to allocate a bio if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 			 * __GFP_DIRECT_RECLAIM is set, see bio_alloc_bioset().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 			bio = bio_alloc(GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 				min_t(int, nr_pages, BIO_MAX_PAGES));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 			fscrypt_set_bio_crypt_ctx(bio, inode, next_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 						  GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 			ext4_set_bio_post_read_ctx(bio, inode, page->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 			bio_set_dev(bio, bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 			bio->bi_iter.bi_sector = blocks[0] << (blkbits - 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 			bio->bi_end_io = mpage_end_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 			bio_set_op_attrs(bio, REQ_OP_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 						rac ? REQ_RAHEAD : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		length = first_hole << blkbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		if (bio_add_page(bio, page, length, 0) < length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 			goto submit_and_realloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		if (((map.m_flags & EXT4_MAP_BOUNDARY) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		     (relative_block == map.m_len)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		    (first_hole != blocks_per_page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 			ext4_submit_bio_read(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 			bio = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 			last_block_in_bio = blocks[blocks_per_page - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		goto next_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	confused:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		if (bio) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 			ext4_submit_bio_read(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 			bio = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		if (!PageUptodate(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 			block_read_full_page(page, ext4_get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 			unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	next_page:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		if (rac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 			put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	if (bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		ext4_submit_bio_read(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) int __init ext4_init_post_read_processing(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	bio_post_read_ctx_cache =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		kmem_cache_create("ext4_bio_post_read_ctx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 				  sizeof(struct bio_post_read_ctx), 0, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	if (!bio_post_read_ctx_cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	bio_post_read_ctx_pool =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		mempool_create_slab_pool(NUM_PREALLOC_POST_READ_CTXS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 					 bio_post_read_ctx_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	if (!bio_post_read_ctx_pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		goto fail_free_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) fail_free_cache:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	kmem_cache_destroy(bio_post_read_ctx_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) void ext4_exit_post_read_processing(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	mempool_destroy(bio_post_read_ctx_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	kmem_cache_destroy(bio_post_read_ctx_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }