]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
block: bounce: don't access bio->bi_io_vec in copy_to_high_bio_irq
authorMing Lei <ming.lei@redhat.com>
Mon, 18 Dec 2017 12:22:07 +0000 (20:22 +0800)
committerJens Axboe <axboe@kernel.dk>
Sat, 6 Jan 2018 16:18:00 +0000 (09:18 -0700)
Firstly this patch introduces BVEC_ITER_ALL_INIT for iterating one bio
from start to end.

As we need to support multipage bvecs, don't access bio->bi_io_vec
in copy_to_high_bio_irq(), and just use the standard iterator for that.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/bounce.c
include/linux/bvec.h

index 0274c31d6c05ae5099e353d7dfe963b2db94b20c..c35a3d7f05281e95822e26b98b19eedb275475a7 100644 (file)
@@ -113,24 +113,30 @@ int init_emergency_isa_pool(void)
 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 bio_vec tovec, fromvec;
        struct bvec_iter iter;
+       /*
+        * The bio of @from is created by bounce, so we can iterate
+        * its bvec from start to end, but the @from->bi_iter can't be
+        * trusted because it might be changed by splitting.
+        */
+       struct bvec_iter from_iter = BVEC_ITER_ALL_INIT;
 
        bio_for_each_segment(tovec, to, iter) {
-               if (tovec.bv_page != fromvec->bv_page) {
+               fromvec = bio_iter_iovec(from, from_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) +
+                       vfrom = page_address(fromvec.bv_page) +
                                tovec.bv_offset;
 
                        bounce_copy_vec(&tovec, vfrom);
                        flush_dcache_page(tovec.bv_page);
                }
-
-               fromvec++;
+               bio_advance_iter(from, &from_iter, tovec.bv_len);
        }
 }
 
index ec8a4d7af6bda55586bc0b0221b3dcfe6e5ab487..fe7a22dd133b5a3c62833fd2539668d99f20b6f8 100644 (file)
@@ -125,4 +125,13 @@ static inline bool bvec_iter_rewind(const struct bio_vec *bv,
                ((bvl = bvec_iter_bvec((bio_vec), (iter))), 1); \
             bvec_iter_advance((bio_vec), &(iter), (bvl).bv_len))
 
+/* for iterating one bio from start to end */
+#define BVEC_ITER_ALL_INIT (struct bvec_iter)                          \
+{                                                                      \
+       .bi_sector      = 0,                                            \
+       .bi_size        = UINT_MAX,                                     \
+       .bi_idx         = 0,                                            \
+       .bi_bvec_done   = 0,                                            \
+}
+
 #endif /* __LINUX_BVEC_ITER_H */