summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2018-09-24 03:43:50 -0400
committerJens Axboe <axboe@kernel.dk>2018-09-24 14:33:54 -0400
commit6a9f5f240adfdced863a098d34f8f05ca6ab9d5f (patch)
treeeb81b3a3073e9c03c03170468f2ba43ed7f43487
parent27ca1d4ed04ea29dc77b47190a3cc82697023e76 (diff)
block: simplify BIOVEC_PHYS_MERGEABLE
Turn the macro into an inline, move it to blk.h and simplify the arch hooks a bit. Also rename the function to biovec_phys_mergeable as there is no need to shout. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--arch/arm/include/asm/io.h5
-rw-r--r--arch/arm64/include/asm/io.h5
-rw-r--r--arch/x86/include/asm/io.h5
-rw-r--r--block/bio.c2
-rw-r--r--block/blk-integrity.c4
-rw-r--r--block/blk-merge.c10
-rw-r--r--block/blk.h14
-rw-r--r--include/linux/bio.h13
8 files changed, 28 insertions, 30 deletions
diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h
index 2cfbc531f63b..3c835d6263fa 100644
--- a/arch/arm/include/asm/io.h
+++ b/arch/arm/include/asm/io.h
@@ -469,9 +469,8 @@ extern void pci_iounmap(struct pci_dev *dev, void __iomem *addr);
469struct bio_vec; 469struct bio_vec;
470extern bool xen_biovec_phys_mergeable(const struct bio_vec *vec1, 470extern bool xen_biovec_phys_mergeable(const struct bio_vec *vec1,
471 const struct bio_vec *vec2); 471 const struct bio_vec *vec2);
472#define BIOVEC_PHYS_MERGEABLE(vec1, vec2) \ 472#define ARCH_BIOVEC_PHYS_MERGEABLE(vec1, vec2) \
473 (__BIOVEC_PHYS_MERGEABLE(vec1, vec2) && \ 473 (!xen_domain() || xen_biovec_phys_mergeable(vec1, vec2))
474 (!xen_domain() || xen_biovec_phys_mergeable(vec1, vec2)))
475 474
476#ifdef CONFIG_MMU 475#ifdef CONFIG_MMU
477#define ARCH_HAS_VALID_PHYS_ADDR_RANGE 476#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h
index 35b2e50f17fb..774e03ea1bb0 100644
--- a/arch/arm64/include/asm/io.h
+++ b/arch/arm64/include/asm/io.h
@@ -208,9 +208,8 @@ extern int devmem_is_allowed(unsigned long pfn);
208struct bio_vec; 208struct bio_vec;
209extern bool xen_biovec_phys_mergeable(const struct bio_vec *vec1, 209extern bool xen_biovec_phys_mergeable(const struct bio_vec *vec1,
210 const struct bio_vec *vec2); 210 const struct bio_vec *vec2);
211#define BIOVEC_PHYS_MERGEABLE(vec1, vec2) \ 211#define ARCH_BIOVEC_PHYS_MERGEABLE(vec1, vec2) \
212 (__BIOVEC_PHYS_MERGEABLE(vec1, vec2) && \ 212 (!xen_domain() || xen_biovec_phys_mergeable(vec1, vec2))
213 (!xen_domain() || xen_biovec_phys_mergeable(vec1, vec2)))
214 213
215#endif /* __KERNEL__ */ 214#endif /* __KERNEL__ */
216#endif /* __ASM_IO_H */ 215#endif /* __ASM_IO_H */
diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
index 6de64840dd22..7c6106216d9c 100644
--- a/arch/x86/include/asm/io.h
+++ b/arch/x86/include/asm/io.h
@@ -376,9 +376,8 @@ struct bio_vec;
376extern bool xen_biovec_phys_mergeable(const struct bio_vec *vec1, 376extern bool xen_biovec_phys_mergeable(const struct bio_vec *vec1,
377 const struct bio_vec *vec2); 377 const struct bio_vec *vec2);
378 378
379#define BIOVEC_PHYS_MERGEABLE(vec1, vec2) \ 379#define ARCH_BIOVEC_PHYS_MERGEABLE(vec1, vec2) \
380 (__BIOVEC_PHYS_MERGEABLE(vec1, vec2) && \ 380 (!xen_domain() || xen_biovec_phys_mergeable(vec1, vec2))
381 (!xen_domain() || xen_biovec_phys_mergeable(vec1, vec2)))
382#endif /* CONFIG_XEN */ 381#endif /* CONFIG_XEN */
383 382
384#define IO_SPACE_LIMIT 0xffff 383#define IO_SPACE_LIMIT 0xffff
diff --git a/block/bio.c b/block/bio.c
index 1cd47f218200..81d90b839e05 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -731,7 +731,7 @@ int bio_add_pc_page(struct request_queue *q, struct bio *bio, struct page
731 } 731 }
732 732
733 /* If we may be able to merge these biovecs, force a recount */ 733 /* If we may be able to merge these biovecs, force a recount */
734 if (bio->bi_vcnt > 1 && (BIOVEC_PHYS_MERGEABLE(bvec-1, bvec))) 734 if (bio->bi_vcnt > 1 && biovec_phys_mergeable(bvec-1, bvec))
735 bio_clear_flag(bio, BIO_SEG_VALID); 735 bio_clear_flag(bio, BIO_SEG_VALID);
736 736
737 done: 737 done:
diff --git a/block/blk-integrity.c b/block/blk-integrity.c
index 6121611e1316..0f7267916509 100644
--- a/block/blk-integrity.c
+++ b/block/blk-integrity.c
@@ -49,7 +49,7 @@ int blk_rq_count_integrity_sg(struct request_queue *q, struct bio *bio)
49 bio_for_each_integrity_vec(iv, bio, iter) { 49 bio_for_each_integrity_vec(iv, bio, iter) {
50 50
51 if (prev) { 51 if (prev) {
52 if (!BIOVEC_PHYS_MERGEABLE(&ivprv, &iv)) 52 if (!biovec_phys_mergeable(&ivprv, &iv))
53 goto new_segment; 53 goto new_segment;
54 54
55 if (!BIOVEC_SEG_BOUNDARY(q, &ivprv, &iv)) 55 if (!BIOVEC_SEG_BOUNDARY(q, &ivprv, &iv))
@@ -95,7 +95,7 @@ int blk_rq_map_integrity_sg(struct request_queue *q, struct bio *bio,
95 bio_for_each_integrity_vec(iv, bio, iter) { 95 bio_for_each_integrity_vec(iv, bio, iter) {
96 96
97 if (prev) { 97 if (prev) {
98 if (!BIOVEC_PHYS_MERGEABLE(&ivprv, &iv)) 98 if (!biovec_phys_mergeable(&ivprv, &iv))
99 goto new_segment; 99 goto new_segment;
100 100
101 if (!BIOVEC_SEG_BOUNDARY(q, &ivprv, &iv)) 101 if (!BIOVEC_SEG_BOUNDARY(q, &ivprv, &iv))
diff --git a/block/blk-merge.c b/block/blk-merge.c
index ad8a226347a6..5e63e8259f92 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -21,7 +21,7 @@ static inline bool bios_segs_mergeable(struct request_queue *q,
21 struct bio *prev, struct bio_vec *prev_last_bv, 21 struct bio *prev, struct bio_vec *prev_last_bv,
22 struct bio_vec *next_first_bv) 22 struct bio_vec *next_first_bv)
23{ 23{
24 if (!BIOVEC_PHYS_MERGEABLE(prev_last_bv, next_first_bv)) 24 if (!biovec_phys_mergeable(prev_last_bv, next_first_bv))
25 return false; 25 return false;
26 if (!BIOVEC_SEG_BOUNDARY(q, prev_last_bv, next_first_bv)) 26 if (!BIOVEC_SEG_BOUNDARY(q, prev_last_bv, next_first_bv))
27 return false; 27 return false;
@@ -199,7 +199,7 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
199 if (bvprvp && blk_queue_cluster(q)) { 199 if (bvprvp && blk_queue_cluster(q)) {
200 if (seg_size + bv.bv_len > queue_max_segment_size(q)) 200 if (seg_size + bv.bv_len > queue_max_segment_size(q))
201 goto new_segment; 201 goto new_segment;
202 if (!BIOVEC_PHYS_MERGEABLE(bvprvp, &bv)) 202 if (!biovec_phys_mergeable(bvprvp, &bv))
203 goto new_segment; 203 goto new_segment;
204 if (!BIOVEC_SEG_BOUNDARY(q, bvprvp, &bv)) 204 if (!BIOVEC_SEG_BOUNDARY(q, bvprvp, &bv))
205 goto new_segment; 205 goto new_segment;
@@ -332,7 +332,7 @@ static unsigned int __blk_recalc_rq_segments(struct request_queue *q,
332 if (seg_size + bv.bv_len 332 if (seg_size + bv.bv_len
333 > queue_max_segment_size(q)) 333 > queue_max_segment_size(q))
334 goto new_segment; 334 goto new_segment;
335 if (!BIOVEC_PHYS_MERGEABLE(&bvprv, &bv)) 335 if (!biovec_phys_mergeable(&bvprv, &bv))
336 goto new_segment; 336 goto new_segment;
337 if (!BIOVEC_SEG_BOUNDARY(q, &bvprv, &bv)) 337 if (!BIOVEC_SEG_BOUNDARY(q, &bvprv, &bv))
338 goto new_segment; 338 goto new_segment;
@@ -414,7 +414,7 @@ static int blk_phys_contig_segment(struct request_queue *q, struct bio *bio,
414 bio_get_last_bvec(bio, &end_bv); 414 bio_get_last_bvec(bio, &end_bv);
415 bio_get_first_bvec(nxt, &nxt_bv); 415 bio_get_first_bvec(nxt, &nxt_bv);
416 416
417 if (!BIOVEC_PHYS_MERGEABLE(&end_bv, &nxt_bv)) 417 if (!biovec_phys_mergeable(&end_bv, &nxt_bv))
418 return 0; 418 return 0;
419 419
420 /* 420 /*
@@ -439,7 +439,7 @@ __blk_segment_map_sg(struct request_queue *q, struct bio_vec *bvec,
439 if ((*sg)->length + nbytes > queue_max_segment_size(q)) 439 if ((*sg)->length + nbytes > queue_max_segment_size(q))
440 goto new_segment; 440 goto new_segment;
441 441
442 if (!BIOVEC_PHYS_MERGEABLE(bvprv, bvec)) 442 if (!biovec_phys_mergeable(bvprv, bvec))
443 goto new_segment; 443 goto new_segment;
444 if (!BIOVEC_SEG_BOUNDARY(q, bvprv, bvec)) 444 if (!BIOVEC_SEG_BOUNDARY(q, bvprv, bvec))
445 goto new_segment; 445 goto new_segment;
diff --git a/block/blk.h b/block/blk.h
index 63035c95689c..aed99cbc1bca 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -149,6 +149,20 @@ static inline void blk_queue_enter_live(struct request_queue *q)
149 percpu_ref_get(&q->q_usage_counter); 149 percpu_ref_get(&q->q_usage_counter);
150} 150}
151 151
152#ifndef ARCH_BIOVEC_PHYS_MERGEABLE
153#define ARCH_BIOVEC_PHYS_MERGEABLE(vec1, vec2) true
154#endif
155
156static inline bool biovec_phys_mergeable(const struct bio_vec *vec1,
157 const struct bio_vec *vec2)
158{
159 if (bvec_to_phys(vec1) + vec1->bv_len != bvec_to_phys(vec2))
160 return false;
161 if (!ARCH_BIOVEC_PHYS_MERGEABLE(vec1, vec2))
162 return false;
163 return true;
164}
165
152static inline bool __bvec_gap_to_prev(struct request_queue *q, 166static inline bool __bvec_gap_to_prev(struct request_queue *q,
153 struct bio_vec *bprv, unsigned int offset) 167 struct bio_vec *bprv, unsigned int offset)
154{ 168{
diff --git a/include/linux/bio.h b/include/linux/bio.h
index e973876625a8..e2adb96346f0 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -140,19 +140,6 @@ static inline bool bio_full(struct bio *bio)
140/* 140/*
141 * merge helpers etc 141 * merge helpers etc
142 */ 142 */
143
144/* Default implementation of BIOVEC_PHYS_MERGEABLE */
145#define __BIOVEC_PHYS_MERGEABLE(vec1, vec2) \
146 ((bvec_to_phys((vec1)) + (vec1)->bv_len) == bvec_to_phys((vec2)))
147
148/*
149 * allow arch override, for eg virtualized architectures (put in asm/io.h)
150 */
151#ifndef BIOVEC_PHYS_MERGEABLE
152#define BIOVEC_PHYS_MERGEABLE(vec1, vec2) \
153 __BIOVEC_PHYS_MERGEABLE(vec1, vec2)
154#endif
155
156#define __BIO_SEG_BOUNDARY(addr1, addr2, mask) \ 143#define __BIO_SEG_BOUNDARY(addr1, addr2, mask) \
157 (((addr1) | (mask)) == (((addr2) - 1) | (mask))) 144 (((addr1) | (mask)) == (((addr2) - 1) | (mask)))
158#define BIOVEC_SEG_BOUNDARY(q, b1, b2) \ 145#define BIOVEC_SEG_BOUNDARY(q, b1, b2) \