cregit-Linux how code gets into the kernel

Release 4.9 block/bounce.c

Directory: block
/* bounce buffer handling for block devices
 *
 * - Split from highmem.c
 */


#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/mm.h>
#include <linux/export.h>
#include <linux/swap.h>
#include <linux/gfp.h>
#include <linux/bio.h>
#include <linux/pagemap.h>
#include <linux/mempool.h>
#include <linux/blkdev.h>
#include <linux/backing-dev.h>
#include <linux/init.h>
#include <linux/hash.h>
#include <linux/highmem.h>
#include <linux/bootmem.h>
#include <linux/printk.h>
#include <asm/tlbflush.h>

#include <trace/events/block.h>


#define POOL_SIZE	64

#define ISA_POOL_SIZE	16



static mempool_t *page_pool, *isa_page_pool;

#if defined(CONFIG_HIGHMEM) || defined(CONFIG_NEED_BOUNCE_POOL)

static __init int init_emergency_pool(void) { #if defined(CONFIG_HIGHMEM) && !defined(CONFIG_MEMORY_HOTPLUG) if (max_pfn <= max_low_pfn) return 0; #endif page_pool = mempool_create_page_pool(POOL_SIZE, 0); BUG_ON(!page_pool); pr_info("pool size: %d pages\n", POOL_SIZE); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells3866.67%125.00%
chris metcalfchris metcalf1119.30%125.00%
david vrabeldavid vrabel610.53%125.00%
mitchel humpherysmitchel humpherys23.51%125.00%
Total57100.00%4100.00%

__initcall(init_emergency_pool); #endif #ifdef CONFIG_HIGHMEM /* * highmem version, map in to vec */
static void bounce_copy_vec(struct bio_vec *to, unsigned char *vfrom) { unsigned long flags; unsigned char *vto; local_irq_save(flags); vto = kmap_atomic(to->bv_page); memcpy(vto + to->bv_offset, vfrom, to->bv_len); kunmap_atomic(vto); local_irq_restore(flags); }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells64100.00%1100.00%
Total64100.00%1100.00%

#else /* CONFIG_HIGHMEM */ #define bounce_copy_vec(to, vfrom) \ memcpy(page_address((to)->bv_page) + (to)->bv_offset, vfrom, (to)->bv_len) #endif /* CONFIG_HIGHMEM */ /* * allocate pages in the DMA region for the ISA pool */
static void *mempool_alloc_pages_isa(gfp_t gfp_mask, void *data) { return mempool_alloc_pages(gfp_mask | GFP_DMA, data); }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells24100.00%1100.00%
Total24100.00%1100.00%

/* * gets called "every" time someone init's a queue with BLK_BOUNCE_ISA * as the max address, so check if the pool has already been created. */
int init_emergency_isa_pool(void) { if (isa_page_pool) return 0; isa_page_pool = mempool_create(ISA_POOL_SIZE, mempool_alloc_pages_isa, mempool_free_pages, (void *) 0); BUG_ON(!isa_page_pool); pr_info("isa pool size: %d pages\n", ISA_POOL_SIZE); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells4595.74%150.00%
mitchel humpherysmitchel humpherys24.26%150.00%
Total47100.00%2100.00%

/* * Simple bounce buffer support for highmem pages. Depending on the * queue gfp mask set, *to may or may not be a highmem page. kmap it * always, it will do the Right Thing */
static void copy_to_high_bio_irq(struct bio *to, struct bio *from) { unsigned char *vfrom; struct bio_vec tovec, *fromvec = from->bi_io_vec; struct bvec_iter iter; bio_for_each_segment(tovec, to, iter) { if (tovec.bv_page != fromvec->bv_page) { /* * fromvec->bv_offset and fromvec->bv_len might have * been modified by the block layer, so use the original * copy, bounce_copy_vec already uses tovec->bv_len */ vfrom = page_address(fromvec->bv_page) + tovec.bv_offset; bounce_copy_vec(&tovec, vfrom); flush_dcache_page(tovec.bv_page); } fromvec++; } }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells6572.22%125.00%
kent overstreetkent overstreet2022.22%250.00%
gary kinggary king55.56%125.00%
Total90100.00%4100.00%


static void bounce_end_io(struct bio *bio, mempool_t *pool) { struct bio *bio_orig = bio->bi_private; struct bio_vec *bvec, *org_vec; int i; int start = bio_orig->bi_iter.bi_idx; /* * free up bounce indirect pages used */ bio_for_each_segment_all(bvec, bio, i) { org_vec = bio_orig->bi_io_vec + i + start; if (bvec->bv_page == org_vec->bv_page) continue; dec_zone_page_state(bvec->bv_page, NR_BOUNCE); mempool_free(bvec->bv_page, pool); } bio_orig->bi_error = bio->bi_error; bio_endio(bio_orig); bio_put(bio); }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells9282.14%125.00%
ming leiming lei119.82%125.00%
christoph hellwigchristoph hellwig87.14%125.00%
kent overstreetkent overstreet10.89%125.00%
Total112100.00%4100.00%


static void bounce_end_io_write(struct bio *bio) { bounce_end_io(bio, page_pool); }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells1794.44%150.00%
neil brownneil brown15.56%150.00%
Total18100.00%2100.00%


static void bounce_end_io_write_isa(struct bio *bio) { bounce_end_io(bio, isa_page_pool); }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells1794.44%150.00%
neil brownneil brown15.56%150.00%
Total18100.00%2100.00%


static void __bounce_end_io_read(struct bio *bio, mempool_t *pool) { struct bio *bio_orig = bio->bi_private; if (!bio->bi_error) copy_to_high_bio_irq(bio_orig, bio); bounce_end_io(bio, pool); }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells4395.56%150.00%
christoph hellwigchristoph hellwig24.44%150.00%
Total45100.00%2100.00%


static void bounce_end_io_read(struct bio *bio) { __bounce_end_io_read(bio, page_pool); }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells1794.44%150.00%
neil brownneil brown15.56%150.00%
Total18100.00%2100.00%


static void bounce_end_io_read_isa(struct bio *bio) { __bounce_end_io_read(bio, isa_page_pool); }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells1794.44%150.00%
neil brownneil brown15.56%150.00%
Total18100.00%2100.00%


static void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig, mempool_t *pool) { struct bio *bio; int rw = bio_data_dir(*bio_orig); struct bio_vec *to, from; struct bvec_iter iter; unsigned i; bio_for_each_segment(from, *bio_orig, iter) if (page_to_pfn(from.bv_page) > queue_bounce_pfn(q)) goto bounce; return; bounce: bio = bio_clone_bioset(*bio_orig, GFP_NOIO, fs_bio_set); bio_for_each_segment_all(to, bio, i) { struct page *page = to->bv_page; if (page_to_pfn(page) <= queue_bounce_pfn(q)) continue; to->bv_page = mempool_alloc(pool, q->bounce_gfp); inc_zone_page_state(to->bv_page, NR_BOUNCE); if (rw == WRITE) { char *vto, *vfrom; flush_dcache_page(page); vto = page_address(to->bv_page) + to->bv_offset; vfrom = kmap_atomic(page) + to->bv_offset; memcpy(vto, vfrom, to->bv_len); kunmap_atomic(vfrom); } } trace_block_bio_bounce(q, *bio_orig); bio->bi_flags |= (1 << BIO_BOUNCED); if (pool == page_pool) { bio->bi_end_io = bounce_end_io_write; if (rw == READ) bio->bi_end_io = bounce_end_io_read; } else { bio->bi_end_io = bounce_end_io_write_isa; if (rw == READ) bio->bi_end_io = bounce_end_io_read_isa; } bio->bi_private = *bio_orig; *bio_orig = bio; }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells19770.36%110.00%
kent overstreetkent overstreet5419.29%330.00%
jens axboejens axboe165.71%330.00%
wang yanqingwang yanqing93.21%110.00%
martin k. petersenmartin k. petersen31.07%110.00%
arnaldo carvalho de meloarnaldo carvalho de melo10.36%110.00%
Total280100.00%10100.00%


void blk_queue_bounce(struct request_queue *q, struct bio **bio_orig) { mempool_t *pool; /* * Data-less bio, nothing to bounce */ if (!bio_has_data(*bio_orig)) return; /* * for non-isa bounce case, just check if the bounce pfn is equal * to or bigger than the highest pfn in the system -- in that case, * don't waste time iterating over bio segments */ if (!(q->bounce_gfp & GFP_DMA)) { if (queue_bounce_pfn(q) >= blk_max_pfn) return; pool = page_pool; } else { BUG_ON(!isa_page_pool); pool = isa_page_pool; } /* * slow path */ __blk_queue_bounce(q, bio_orig, pool); }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells6680.49%120.00%
jens axboejens axboe1315.85%360.00%
martin k. petersenmartin k. petersen33.66%120.00%
Total82100.00%5100.00%

EXPORT_SYMBOL(blk_queue_bounce);

Overall Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells78178.81%14.17%
kent overstreetkent overstreet757.57%416.67%
jens axboejens axboe292.93%520.83%
chris metcalfchris metcalf262.62%14.17%
mitchel humpherysmitchel humpherys141.41%14.17%
ming leiming lei111.11%14.17%
christoph hellwigchristoph hellwig101.01%14.17%
david vrabeldavid vrabel90.91%14.17%
wang yanqingwang yanqing90.91%14.17%
martin k. petersenmartin k. petersen60.61%14.17%
tejun heotejun heo60.61%28.33%
gary kinggary king50.50%14.17%
neil brownneil brown40.40%14.17%
arnaldo carvalho de meloarnaldo carvalho de melo30.30%14.17%
li zefanli zefan20.20%14.17%
paul gortmakerpaul gortmaker10.10%14.17%
Total991100.00%24100.00%
Directory: block