summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamien Le Moal <damien.lemoal@wdc.com>2019-07-01 01:09:15 -0400
committerJens Axboe <axboe@kernel.dk>2019-07-11 22:04:36 -0400
commitb4c5875d36178e8df409bdce232f270cac89fafe (patch)
tree3dcf8838b6b74b38b4c1db5d154ecee93e15922c
parente7bf90e5afe3aa1d1282c1635a49e17a32c4ecec (diff)
block: Allow mapping of vmalloc-ed buffers
To allow the SCSI subsystem scsi_execute_req() function to issue requests using large buffers that are better allocated with vmalloc() rather than kmalloc(), modify bio_map_kern() to allow passing a buffer allocated with vmalloc(). To do so, detect vmalloc-ed buffers using is_vmalloc_addr(). For vmalloc-ed buffers, flush the buffer using flush_kernel_vmap_range(), use vmalloc_to_page() instead of virt_to_page() to obtain the pages of the buffer, and invalidate the buffer addresses with invalidate_kernel_vmap_range() on completion of read BIOs. This last point is executed using the function bio_invalidate_vmalloc_pages() which is defined only if the architecture defines ARCH_HAS_FLUSH_KERNEL_DCACHE_PAGE, that is, if the architecture actually needs the invalidation done. Fixes: 515ce6061312 ("scsi: sd_zbc: Fix sd_zbc_report_zones() buffer allocation") Fixes: e76239a3748c ("block: add a report_zones method") Cc: stable@vger.kernel.org Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com> Reviewed-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--block/bio.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/block/bio.c b/block/bio.c
index 29cd6cf4da51..299a0e7651ec 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -16,6 +16,7 @@
16#include <linux/workqueue.h> 16#include <linux/workqueue.h>
17#include <linux/cgroup.h> 17#include <linux/cgroup.h>
18#include <linux/blk-cgroup.h> 18#include <linux/blk-cgroup.h>
19#include <linux/highmem.h>
19 20
20#include <trace/events/block.h> 21#include <trace/events/block.h>
21#include "blk.h" 22#include "blk.h"
@@ -1441,8 +1442,22 @@ void bio_unmap_user(struct bio *bio)
1441 bio_put(bio); 1442 bio_put(bio);
1442} 1443}
1443 1444
1445static void bio_invalidate_vmalloc_pages(struct bio *bio)
1446{
1447#ifdef ARCH_HAS_FLUSH_KERNEL_DCACHE_PAGE
1448 if (bio->bi_private && !op_is_write(bio_op(bio))) {
1449 unsigned long i, len = 0;
1450
1451 for (i = 0; i < bio->bi_vcnt; i++)
1452 len += bio->bi_io_vec[i].bv_len;
1453 invalidate_kernel_vmap_range(bio->bi_private, len);
1454 }
1455#endif
1456}
1457
1444static void bio_map_kern_endio(struct bio *bio) 1458static void bio_map_kern_endio(struct bio *bio)
1445{ 1459{
1460 bio_invalidate_vmalloc_pages(bio);
1446 bio_put(bio); 1461 bio_put(bio);
1447} 1462}
1448 1463
@@ -1463,6 +1478,8 @@ struct bio *bio_map_kern(struct request_queue *q, void *data, unsigned int len,
1463 unsigned long end = (kaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT; 1478 unsigned long end = (kaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
1464 unsigned long start = kaddr >> PAGE_SHIFT; 1479 unsigned long start = kaddr >> PAGE_SHIFT;
1465 const int nr_pages = end - start; 1480 const int nr_pages = end - start;
1481 bool is_vmalloc = is_vmalloc_addr(data);
1482 struct page *page;
1466 int offset, i; 1483 int offset, i;
1467 struct bio *bio; 1484 struct bio *bio;
1468 1485
@@ -1470,6 +1487,11 @@ struct bio *bio_map_kern(struct request_queue *q, void *data, unsigned int len,
1470 if (!bio) 1487 if (!bio)
1471 return ERR_PTR(-ENOMEM); 1488 return ERR_PTR(-ENOMEM);
1472 1489
1490 if (is_vmalloc) {
1491 flush_kernel_vmap_range(data, len);
1492 bio->bi_private = data;
1493 }
1494
1473 offset = offset_in_page(kaddr); 1495 offset = offset_in_page(kaddr);
1474 for (i = 0; i < nr_pages; i++) { 1496 for (i = 0; i < nr_pages; i++) {
1475 unsigned int bytes = PAGE_SIZE - offset; 1497 unsigned int bytes = PAGE_SIZE - offset;
@@ -1480,7 +1502,11 @@ struct bio *bio_map_kern(struct request_queue *q, void *data, unsigned int len,
1480 if (bytes > len) 1502 if (bytes > len)
1481 bytes = len; 1503 bytes = len;
1482 1504
1483 if (bio_add_pc_page(q, bio, virt_to_page(data), bytes, 1505 if (!is_vmalloc)
1506 page = virt_to_page(data);
1507 else
1508 page = vmalloc_to_page(data);
1509 if (bio_add_pc_page(q, bio, page, bytes,
1484 offset) < bytes) { 1510 offset) < bytes) {
1485 /* we don't support partial mappings */ 1511 /* we don't support partial mappings */
1486 bio_put(bio); 1512 bio_put(bio);