]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
block: Replace SG_GAPS with new queue limits mask
authorKeith Busch <keith.busch@intel.com>
Thu, 1 Feb 2018 19:37:06 +0000 (11:37 -0800)
committerJack Vogel <jack.vogel@oracle.com>
Wed, 7 Feb 2018 18:06:44 +0000 (10:06 -0800)
The SG_GAPS queue flag caused checks for bio vector alignment against
PAGE_SIZE, but the device may have different constraints. This patch
adds a queue limits so a driver with such constraints can set to allow
requests that would have been unnecessarily split. The new gaps check
takes the request_queue as a parameter to simplify the logic around
invoking this function.

This new limit makes the queue flag redundant, so removing it and
all usage. Device-mappers will inherit the correct settings through
blk_stack_limits().

Signed-off-by: Keith Busch <keith.busch@intel.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@fb.com>
(cherry picked from commit 03100aada96f0645bbcb89aea24c01f02d0ef1fa)

Orabug: 27484719

Conflicts:
        Changes in blk_bio_segment_split() are not picked up
from 03100aada96f0645bbcb89aea24c01f02d0ef1fa as we are not
porting arbitary bio size support.

Signed-off-by: Ashok Vairavan <ashok.vairavan@oracle.com>
Reviewed-by: Kyle Fortin <kyle.fortin@oracle.com>
block/bio.c
block/blk-merge.c
block/blk-settings.c
drivers/md/dm-table.c
drivers/nvme/host/core.c
drivers/scsi/megaraid/megaraid_sas_base.c
include/linux/bio.h
include/linux/blkdev.h

index f4cbd84b0abfe3f9be61dcb1ec77e5750b79ad5e..3b88bd38c9739fa80492fc5a328b2f0dce3acec2 100644 (file)
@@ -770,8 +770,7 @@ static int __bio_add_page(struct request_queue *q, struct bio *bio, struct page
                 * If the queue doesn't support SG gaps and adding this
                 * offset would create a gap, disallow it.
                 */
-               if (q->queue_flags & (1 << QUEUE_FLAG_SG_GAPS) &&
-                   bvec_gap_to_prev(prev, offset))
+               if (bvec_gap_to_prev(q, prev, offset))
                        return 0;
        }
 
index fd3fee81c23ce2f1cdc73d2bf4e76188c90358cb..2030ccb6e5dff0116a500d2cac5941a7c88e3ae4 100644 (file)
@@ -356,12 +356,12 @@ static bool req_no_special_merge(struct request *req)
        return !q->mq_ops && req->special;
 }
 
-static int req_gap_to_prev(struct request *req, struct request *next)
+static int req_gap_to_prev(struct request *req, struct bio *next)
 {
        struct bio *prev = req->biotail;
 
-       return bvec_gap_to_prev(&prev->bi_io_vec[prev->bi_vcnt - 1],
-                               next->bio->bi_io_vec[0].bv_offset);
+       return bvec_gap_to_prev(req->q, &prev->bi_io_vec[prev->bi_vcnt - 1],
+                       next->bi_io_vec[1].bv_offset);
 }
 
 static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
@@ -378,8 +378,7 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
        if (req_no_special_merge(req) || req_no_special_merge(next))
                return 0;
 
-       if (test_bit(QUEUE_FLAG_SG_GAPS, &q->queue_flags) &&
-           req_gap_to_prev(req, next))
+       if (req_gap_to_prev(req, next->bio))
                return 0;
 
        /*
@@ -564,8 +563,6 @@ int blk_attempt_req_merge(struct request_queue *q, struct request *rq,
 
 bool blk_rq_merge_ok(struct request *rq, struct bio *bio)
 {
-       struct request_queue *q = rq->q;
-
        if (!rq_mergeable(rq) || !bio_mergeable(bio))
                return false;
 
@@ -589,13 +586,9 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio)
            !blk_write_same_mergeable(rq->bio, bio))
                return false;
 
-       if (q->queue_flags & (1 << QUEUE_FLAG_SG_GAPS)) {
-               struct bio_vec *bprev;
-
-               bprev = &rq->biotail->bi_io_vec[rq->biotail->bi_vcnt - 1];
-               if (bvec_gap_to_prev(bprev, bio->bi_io_vec[0].bv_offset))
-                       return false;
-       }
+       /* Only check gaps if the bio carries data */
+       if (bio_has_data(bio) && req_gap_to_prev(rq, bio))
+               return false;
 
        return true;
 }
index 5891a1cba4711b1ac6303a94268e61c8e63f8af4..5c3b05c3cbe519c109b9e86a01cafd8f9280c995 100644 (file)
@@ -111,6 +111,7 @@ void blk_set_default_limits(struct queue_limits *lim)
        lim->max_segments = BLK_MAX_SEGMENTS;
        lim->max_integrity_segments = 0;
        lim->seg_boundary_mask = BLK_SEG_BOUNDARY_MASK;
+       lim->virt_boundary_mask = 0;
        lim->max_segment_size = BLK_MAX_SEGMENT_SIZE;
        lim->max_sectors = lim->max_hw_sectors = BLK_SAFE_MAX_SECTORS;
        lim->max_dev_sectors = 0;
@@ -577,6 +578,8 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
 
        t->seg_boundary_mask = min_not_zero(t->seg_boundary_mask,
                                            b->seg_boundary_mask);
+       t->virt_boundary_mask = min_not_zero(t->virt_boundary_mask,
+                                           b->virt_boundary_mask);
 
        t->max_segments = min_not_zero(t->max_segments, b->max_segments);
        t->max_integrity_segments = min_not_zero(t->max_integrity_segments,
@@ -814,6 +817,17 @@ void blk_queue_segment_boundary(struct request_queue *q, unsigned long mask)
 }
 EXPORT_SYMBOL(blk_queue_segment_boundary);
 
+/**
+ * blk_queue_virt_boundary - set boundary rules for bio merging
+ * @q:  the request queue for the device
+ * @mask:  the memory boundary mask
+ **/
+void blk_queue_virt_boundary(struct request_queue *q, unsigned long mask)
+{
+       q->limits.virt_boundary_mask = mask;
+}
+EXPORT_SYMBOL(blk_queue_virt_boundary);
+
 /**
  * blk_queue_dma_alignment - set dma length and memory alignment
  * @q:     the request queue for the device
index e411ccba0af6127c94ce438b23324b0ca4019d1e..e7837422929ea4898fd79b9321e15686719f734f 100644 (file)
@@ -1400,14 +1400,6 @@ static int queue_supports_sg_merge(struct dm_target *ti, struct dm_dev *dev,
        return q && !test_bit(QUEUE_FLAG_NO_SG_MERGE, &q->queue_flags);
 }
 
-static int queue_supports_sg_gaps(struct dm_target *ti, struct dm_dev *dev,
-                                 sector_t start, sector_t len, void *data)
-{
-       struct request_queue *q = bdev_get_queue(dev->bdev);
-
-       return q && !test_bit(QUEUE_FLAG_SG_GAPS, &q->queue_flags);
-}
-
 static bool dm_table_all_devices_attribute(struct dm_table *t,
                                           iterate_devices_callout_fn func)
 {
@@ -1528,11 +1520,6 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
        else
                queue_flag_set_unlocked(QUEUE_FLAG_NO_SG_MERGE, q);
 
-       if (dm_table_all_devices_attribute(t, queue_supports_sg_gaps))
-               queue_flag_clear_unlocked(QUEUE_FLAG_SG_GAPS, q);
-       else
-               queue_flag_set_unlocked(QUEUE_FLAG_SG_GAPS, q);
-
        dm_table_set_integrity(t);
 
        /*
index 92bfaa3f34ed36a49a457aa4c364d7ce849c4b14..9ed9f7e9cba430a5f72e3767cf63eb3ded3631e9 100644 (file)
@@ -1059,6 +1059,9 @@ static void nvme_set_queue_limits(struct nvme_ctrl *ctrl,
                blk_queue_chunk_sectors(q, ctrl->stripe_size >> 9);
        if (ctrl->vwc & NVME_CTRL_VWC_PRESENT)
                vwc = true;
+
+       blk_queue_virt_boundary(q, ctrl->page_size - 1);
+
        blk_queue_write_cache(q, vwc, vwc);
 }
 
@@ -1430,7 +1433,6 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
        if (IS_ERR(ns->queue))
                goto out_release_instance;
        queue_flag_set_unlocked(QUEUE_FLAG_NONROT, ns->queue);
-       queue_flag_set_unlocked(QUEUE_FLAG_SG_GAPS, ns->queue);
        ns->queue->queuedata = ns;
        ns->ctrl = ctrl;
 
index 25953016116d94c41e9948eb99176ea38aaf3c54..27988b311366c3fcff8b979c5d3b77a73c1bb0c7 100644 (file)
@@ -1826,9 +1826,7 @@ megasas_set_nvme_device_properties(struct scsi_device *sdev, u32 max_io_size)
        blk_queue_max_hw_sectors(sdev->request_queue, (max_io_size / 512));
 
        queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, sdev->request_queue);
-#ifdef QUEUE_FLAG_SG_GAPS
-       queue_flag_set_unlocked(QUEUE_FLAG_SG_GAPS, sdev->request_queue);
-#endif
+       blk_queue_virt_boundary(sdev->request_queue, mr_nvme_pg_size - 1);
 }
 
 
index 0e7d930620a6229c4ea79d4818eee571526a748e..7c6e2009375743e7edb6186367342143503d59e3 100644 (file)
@@ -186,15 +186,6 @@ static inline void *bio_data(struct bio *bio)
 #define BIOVEC_SEG_BOUNDARY(q, b1, b2) \
        __BIO_SEG_BOUNDARY(bvec_to_phys((b1)), bvec_to_phys((b2)) + (b2)->bv_len, queue_segment_boundary((q)))
 
-/*
- * Check if adding a bio_vec after bprv with offset would create a gap in
- * the SG list. Most drivers don't care about this, but some do.
- */
-static inline bool bvec_gap_to_prev(struct bio_vec *bprv, unsigned int offset)
-{
-       return offset || ((bprv->bv_offset + bprv->bv_len) & (PAGE_SIZE - 1));
-}
-
 #define bio_io_error(bio) bio_endio((bio), -EIO)
 
 /*
index 55db2417916a4e7c3bd708dbed7792acee3d05fb..0cd7d34b23073e1ac9ba7d16184381fd9981de5d 100644 (file)
@@ -319,7 +319,7 @@ struct queue_limits {
    * allow extending the structure while preserving ABI.
    */
        UEK_KABI_USE2(1, unsigned int max_dev_sectors, unsigned int unuse)
-        UEK_KABI_RESERVED(2)
+        UEK_KABI_USE(2, unsigned long virt_boundary_mask)
 };
 
 struct request_queue {
@@ -534,7 +534,6 @@ struct request_queue {
 #define QUEUE_FLAG_DEAD        19      /* queue tear-down finished */
 #define QUEUE_FLAG_INIT_DONE   20      /* queue is initialized */
 #define QUEUE_FLAG_NO_SG_MERGE 21      /* don't attempt to merge SG segments*/
-#define QUEUE_FLAG_SG_GAPS     22      /* queue doesn't support SG gaps */
 #define QUEUE_FLAG_POLL               23       /* IO polling enabled if set */
 #define QUEUE_FLAG_WC         24       /* Write back caching */
 #define QUEUE_FLAG_FUA        25       /* device supports FUA writes */
@@ -1060,6 +1059,7 @@ extern int blk_queue_dma_drain(struct request_queue *q,
                               void *buf, unsigned int size);
 extern void blk_queue_lld_busy(struct request_queue *q, lld_busy_fn *fn);
 extern void blk_queue_segment_boundary(struct request_queue *, unsigned long);
+extern void blk_queue_virt_boundary(struct request_queue *, unsigned long);
 extern void blk_queue_prep_rq(struct request_queue *, prep_rq_fn *pfn);
 extern void blk_queue_unprep_rq(struct request_queue *, unprep_rq_fn *ufn);
 extern void blk_queue_merge_bvec(struct request_queue *, merge_bvec_fn *);
@@ -1230,6 +1230,11 @@ static inline unsigned long queue_segment_boundary(struct request_queue *q)
        return q->limits.seg_boundary_mask;
 }
 
+static inline unsigned long queue_virt_boundary(struct request_queue *q)
+{
+       return q->limits.virt_boundary_mask;
+}
+
 static inline unsigned int queue_max_sectors(struct request_queue *q)
 {
        return q->limits.max_sectors;
@@ -1430,6 +1435,19 @@ static inline void put_dev_sector(Sector p)
        page_cache_release(p.v);
 }
 
+/*
+ * Check if adding a bio_vec after bprv with offset would create a gap in
+ * the SG list. Most drivers don't care about this, but some do.
+ */
+static inline bool bvec_gap_to_prev(struct request_queue *q,
+                               struct bio_vec *bprv, unsigned int offset)
+{
+       if (!queue_virt_boundary(q))
+               return false;
+       return offset ||
+               ((bprv->bv_offset + bprv->bv_len) & queue_virt_boundary(q));
+}
+
 struct work_struct;
 int kblockd_schedule_work(struct work_struct *work);
 int kblockd_schedule_delayed_work(struct delayed_work *dwork, unsigned long delay);