clean up DMA draining
Subsystems (3)
Hi all,
currently the dma draining and alignining specific to ATA CDROMs and the UFS driver has its ugly hooks in core block code. Move this out into the scsi and ide drivers instead.
PATCH 1/5 block: remove RQF_COPY_USER
The RQF_COPY_USER is set for bio where the passthrough request mapping helpers decided that bounce buffering is required. It is then used to pad scatterlist for drivers that required it. But given that non-passthrough requests are per definition aligned, and directly mapped pass-through request must be aligned it is not actually required at all.
--- block/blk-map.c | 9 +-------- block/blk-merge.c | 3 +-- block/blk-mq-debugfs.c | 1 - include/linux/blkdev.h | 2 -- 4 files changed, 2 insertions(+), 13 deletions(-)
block/blk-map.c +1 -8
@@ -654,8 +654,6 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq, bio = rq->bio; }while (iov_iter_count (&i)); -if (!bio_flagged (bio,BIO_USER_MAPPED )) - rq->rq_flags |=RQF_COPY_USER ;return 0 ; unmap_rq:
@@ -731,7 +729,6 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf, {int reading =rq_data_dir (rq) ==READ ;unsigned long addr = (unsigned long ) kbuf; -int do_copy =0 ;struct bio *bio, *orig_bio;int ret;
@@ -740,8 +737,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,if (!len || !kbuf)return -EINVAL ; - do_copy = !blk_rq_aligned (q, addr, len) ||object_is_on_stack (kbuf); -if (do_copy) +if (!blk_rq_aligned (q, addr, len) ||object_is_on_stack (kbuf)) bio =bio_copy_kern (q, kbuf, len, gfp_mask, reading);else bio =bio_map_kern (q, kbuf, len, gfp_mask);
@@ -752,9 +748,6 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf, bio->bi_opf &= ~REQ_OP_MASK ; bio->bi_opf |=req_op (rq); -if (do_copy) - rq->rq_flags |=RQF_COPY_USER ; - orig_bio = bio; ret =blk_rq_append_bio (rq, &bio);if (unlikely (ret)) {
block/blk-merge.c +1 -2
@@ -532,8 +532,7 @@ int blk_rq_map_sg(struct request_queue *q, struct request *rq,else if (rq->bio) nsegs =__blk_bios_map_sg (q, rq->bio, sglist, &sg); -if (unlikely (rq->rq_flags &RQF_COPY_USER ) && - (blk_rq_bytes (rq) & q->dma_pad_mask)) { +if (blk_rq_bytes (rq) && (blk_rq_bytes (rq) & q->dma_pad_mask)) {unsigned int pad_len = (q->dma_pad_mask & ~blk_rq_bytes (rq)) +1 ;
block/blk-mq-debugfs.c +0 -1
@@ -292,7 +292,6 @@ static const char *const rqf_name[] = {RQF_NAME (MQ_INFLIGHT ),RQF_NAME (DONTPREP ),RQF_NAME (PREEMPT ), -RQF_NAME (COPY_USER ),RQF_NAME (FAILED ),RQF_NAME (QUIET ), RQF_NAME(ELVPRIV),
include/linux/blkdev.h +0 -2
@@ -82,8 +82,6 @@ typedef __u32 __bitwise req_flags_t;/* set for "ide_preempt" requests and also for requests for which the SCSI "quiesce" state must be ignored. */ #define RQF_PREEMPT ((__force req_flags_t)(1 << 8)) -/* contains copies of user pages */ -#define RQF_COPY_USER ((__force req_flags_t)(1 << 9))/* vaguely specified driver internal error. Ignored by the block layer */ #define RQF_FAILED ((__force req_flags_t)(1 << 10))/* don't warn about errors */
Signature · 1 line
2.25.1
PATCH 2/5 block: provide a blk_rq_map_sg variant that returns the last element
In reply to Christoph HellwigTo be able to move some of the special purpose hacks in blk_rq_map_sg into the callers we need a variant that returns the last mapped S/G list element to the caller. Add that variant as __blk_rq_map_sg and make blk_rq_map_sg a trivial inline wrapper around it.
--- block/blk-merge.c | 25 ++++++++++++------------- include/linux/blkdev.h | 10 +++++++++- 2 files changed, 21 insertions(+), 14 deletions(-)
block/blk-merge.c +12 -13
@@ -519,24 +519,23 @@ static int __blk_bios_map_sg(struct request_queue *q, struct bio *bio,* map a request to scatterlist, return number of sg entries setup. Caller * must make sure sg can hold rq->nr_phys_segments entries */ -int blk_rq_map_sg (struct request_queue *q,struct request *rq, -struct scatterlist *sglist) +int __blk_rq_map_sg (struct request_queue *q,struct request *rq, +struct scatterlist *sglist,struct scatterlist **last_sg) { -struct scatterlist *sg =NULL ;int nsegs =0 ;if (rq->rq_flags &RQF_SPECIAL_PAYLOAD ) - nsegs =__blk_bvec_map_sg (rq->special_vec, sglist, &sg); + nsegs =__blk_bvec_map_sg (rq->special_vec, sglist, last_sg);else if (rq->bio &&bio_op (rq->bio) ==REQ_OP_WRITE_SAME ) - nsegs =__blk_bvec_map_sg (bio_iovec (rq->bio), sglist, &sg); + nsegs =__blk_bvec_map_sg (bio_iovec (rq->bio), sglist, last_sg);else if (rq->bio) - nsegs =__blk_bios_map_sg (q, rq->bio, sglist, &sg); + nsegs =__blk_bios_map_sg (q, rq->bio, sglist, last_sg);if (blk_rq_bytes (rq) && (blk_rq_bytes (rq) & q->dma_pad_mask)) {unsigned int pad_len = (q->dma_pad_mask & ~blk_rq_bytes (rq)) +1 ; - sg->length += pad_len; + (*last_sg)->length += pad_len; rq->extra_len += pad_len; }
@@ -544,9 +543,9 @@ int blk_rq_map_sg(struct request_queue *q, struct request *rq,if (op_is_write (req_op (rq)))memset (q->dma_drain_buffer,0 , q->dma_drain_size); -sg_unmark_end (sg); - sg =sg_next (sg); -sg_set_page (sg,virt_to_page (q->dma_drain_buffer), +sg_unmark_end (*last_sg); + *last_sg =sg_next (*last_sg); +sg_set_page (*last_sg,virt_to_page (q->dma_drain_buffer), q->dma_drain_size, ((unsigned long )q->dma_drain_buffer) & (PAGE_SIZE -1 ));
@@ -554,8 +553,8 @@ int blk_rq_map_sg(struct request_queue *q, struct request *rq, rq->extra_len += q->dma_drain_size; } -if (sg) -sg_mark_end (sg); +if (*last_sg) +sg_mark_end (*last_sg);/* * Something must have been wrong if the figured number of
@@ -565,7 +564,7 @@ int blk_rq_map_sg(struct request_queue *q, struct request *rq,return nsegs; } -EXPORT_SYMBOL (blk_rq_map_sg); +EXPORT_SYMBOL (__blk_rq_map_sg);static inline int ll_new_hw_segment (struct request *req,struct bio *bio,unsigned int nr_phys_segs)
include/linux/blkdev.h +9 -1
@@ -1136,7 +1136,15 @@ static inline unsigned short blk_rq_nr_discard_segments(struct request *rq) return max_t(unsigned short, rq->nr_phys_segments, 1); } -extern int blk_rq_map_sg (struct request_queue *,struct request *,struct scatterlist *); +int __blk_rq_map_sg (struct request_queue *q,struct request *rq, +struct scatterlist *sglist,struct scatterlist **last_sg); +static inline int blk_rq_map_sg (struct request_queue *q,struct request *rq, +struct scatterlist *sglist) +{ +struct scatterlist *last_sg =NULL ; + +return __blk_rq_map_sg (q, rq, sglist, &last_sg); +}extern void blk_dump_rq_flags (struct request *,char *);extern long nr_blockdev_pages (void );
Signature · 1 line
2.25.1
PATCH 3/5 scsi: merge scsi_init_sgtable into scsi_init_io
In reply to Christoph Hellwigscsi_init_io is the only caller of scsi_init_sgtable. Merge the two function to make upcoming changes a little easier.
--- drivers/scsi/scsi_lib.c | 46 ++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 28 deletions(-)
drivers/scsi/scsi_lib.c +18 -28
@@ -978,30 +978,6 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)scsi_io_completion_action (cmd, result); } -static blk_status_t scsi_init_sgtable (struct request *req, -struct scsi_data_buffer *sdb) -{ -int count; - -/* -* If sg table allocation fails, requeue request later. -*/ -if (unlikely (sg_alloc_table_chained (&sdb->table, -blk_rq_nr_phys_segments (req), sdb->table.sgl, -SCSI_INLINE_SG_CNT ))) -return BLK_STS_RESOURCE ; - -/* -* Next, walk the list, and fill in the addresses and sizes of -* each segment. -*/ - count =blk_rq_map_sg (req->q, req, sdb->table.sgl); -BUG_ON (count > sdb->table.nents); - sdb->table.nents = count; - sdb->length =blk_rq_payload_bytes (req); -return BLK_STS_OK ; -} -/* * Function: scsi_init_io() *
@@ -1017,17 +993,31 @@ blk_status_t scsi_init_io(struct scsi_cmnd *cmd) {struct request *rq = cmd->request;blk_status_t ret; +int count;if (WARN_ON_ONCE (!blk_rq_nr_phys_segments (rq)))return BLK_STS_IOERR ; - ret =scsi_init_sgtable (rq, &cmd->sdb); -if (ret) -return ret; +/* +* If sg table allocation fails, requeue request later. +*/ +if (unlikely (sg_alloc_table_chained (&cmd->sdb.table, +blk_rq_nr_phys_segments (rq), cmd->sdb.table.sgl, +SCSI_INLINE_SG_CNT ))) +return BLK_STS_RESOURCE ; + +/* +* Next, walk the list, and fill in the addresses and sizes of +* each segment. +*/ + count =blk_rq_map_sg (rq->q, rq, cmd->sdb.table.sgl); +BUG_ON (count > cmd->sdb.table.nents); + cmd->sdb.table.nents = count; + cmd->sdb.length =blk_rq_payload_bytes (rq);if (blk_integrity_rq (rq)) {struct scsi_data_buffer *prot_sdb = cmd->prot_sdb; -int ivecs, count; +int ivecs;if (WARN_ON_ONCE (!prot_sdb)) {/*
Signature · 1 line
2.25.1
PATCH 4/5 block: move dma drain handling to scsi
In reply to Christoph HellwigDon't burden the common block code with with specifics of the libata DMA draining mechanism. Instead move most of the code to the scsi midlayer.
That also means the nr_phys_segments adjustments in the blk-mq fast path can go away entirely, given that SCSI never looks at nr_phys_segments after mapping the request to a scatterlist.
wip
--- block/blk-merge.c | 14 -------------- block/blk-mq.c | 11 ----------- block/blk-settings.c | 37 ------------------------------------ drivers/ata/libata-scsi.c | 28 ++++++++++----------------- drivers/scsi/scsi_lib.c | 39 +++++++++++++++++++++++++++++++++----- include/linux/blkdev.h | 7 ------- include/linux/libata.h | 2 ++ include/scsi/scsi_device.h | 3 +++ include/scsi/scsi_host.h | 7 +++++++ 9 files changed, 56 insertions(+), 92 deletions(-)
block/blk-merge.c +0 -14
@@ -539,20 +539,6 @@ int __blk_rq_map_sg(struct request_queue *q, struct request *rq, rq->extra_len += pad_len; } -if (q->dma_drain_size && q->dma_drain_needed (rq)) { -if (op_is_write (req_op (rq))) -memset (q->dma_drain_buffer,0 , q->dma_drain_size); - -sg_unmark_end (*last_sg); - *last_sg =sg_next (*last_sg); -sg_set_page (*last_sg,virt_to_page (q->dma_drain_buffer), - q->dma_drain_size, - ((unsigned long )q->dma_drain_buffer) & - (PAGE_SIZE -1 )); - nsegs++; - rq->extra_len += q->dma_drain_size; - } -if (*last_sg)sg_mark_end (*last_sg);
block/blk-mq.c +0 -11
@@ -667,15 +667,6 @@ void blk_mq_start_request(struct request *rq)blk_add_timer (rq);WRITE_ONCE (rq->state,MQ_RQ_IN_FLIGHT ); -if (q->dma_drain_size &&blk_rq_bytes (rq)) { -/* -* Make sure space for the drain appears. We know we can do -* this because max_hw_segments has been adjusted to be one -* fewer than the device can handle. -*/ - rq->nr_phys_segments++; - } -#ifdef CONFIG_BLK_DEV_INTEGRITY if (blk_integrity_rq (rq) &&req_op (rq) ==REQ_OP_WRITE ) q->integrity.profile->prepare_fn (rq);
@@ -695,8 +686,6 @@ static void __blk_mq_requeue_request(struct request *rq)if (blk_mq_request_started (rq)) {WRITE_ONCE (rq->state,MQ_RQ_IDLE ); rq->rq_flags &= ~RQF_TIMED_OUT ; -if (q->dma_drain_size &&blk_rq_bytes (rq)) - rq->nr_phys_segments--; } }
block/blk-settings.c +0 -37
@@ -651,43 +651,6 @@ void blk_queue_update_dma_pad(struct request_queue *q, unsigned int mask) }EXPORT_SYMBOL (blk_queue_update_dma_pad); -/** -* blk_queue_dma_drain - Set up a drain buffer for excess dma. -* @q: the request queue for the device -* @dma_drain_needed: fn which returns non-zero if drain is necessary -* @buf: physically contiguous buffer -* @size: size of the buffer in bytes -* -* Some devices have excess DMA problems and can't simply discard (or -* zero fill) the unwanted piece of the transfer. They have to have a -* real area of memory to transfer it into. The use case for this is -* ATAPI devices in DMA mode. If the packet command causes a transfer -* bigger than the transfer size some HBAs will lock up if there -* aren't DMA elements to contain the excess transfer. What this API -* does is adjust the queue so that the buf is always appended -* silently to the scatterlist. -* -* Note: This routine adjusts max_hw_segments to make room for appending -* the drain buffer. If you call blk_queue_max_segments() after calling -* this routine, you must set the limit to one fewer than your device -* can support otherwise there won't be room for the drain buffer. -*/ -int blk_queue_dma_drain (struct request_queue *q, -dma_drain_needed_fn *dma_drain_needed, -void *buf,unsigned int size) -{ -if (queue_max_segments (q) <2 ) -return -EINVAL ; -/* make room for appending the drain */ -blk_queue_max_segments (q,queue_max_segments (q) -1 ); - q->dma_drain_needed = dma_drain_needed; - q->dma_drain_buffer = buf; - q->dma_drain_size = size; - -return 0 ; -} -EXPORT_SYMBOL_GPL (blk_queue_dma_drain); -/** * blk_queue_segment_boundary - set boundary rules for segment merging * @q: the request queue for the device
drivers/ata/libata-scsi.c +10 -18
@@ -1017,16 +1017,11 @@ void ata_scsi_sdev_config(struct scsi_device *sdev)* RETURNS: * 1 if ; otherwise, 0. */ -static int atapi_drain_needed (struct request *rq) +bool ata_scsi_dma_need_drain (struct request *rq) { -if (likely (!blk_rq_is_passthrough (rq))) -return 0 ; - -if (!blk_rq_bytes (rq) ||op_is_write (req_op (rq))) -return 0 ; -return atapi_cmd_type (scsi_req (rq)->cmd[0 ]) ==ATAPI_MISC ; } +EXPORT_SYMBOL_GPL (ata_scsi_dma_need_drain);int ata_scsi_dev_config (struct scsi_device *sdev,struct ata_device *dev) {
@@ -1039,21 +1034,21 @@ int ata_scsi_dev_config(struct scsi_device *sdev, struct ata_device *dev)blk_queue_max_hw_sectors (q, dev->max_sectors);if (dev->class ==ATA_DEV_ATAPI ) { -void *buf; - sdev->sector_size =ATA_SECT_SIZE ;/* set DMA padding */ blk_queue_update_dma_pad (q,ATA_DMA_PAD_SZ -1 ); -/* configure draining */ - buf =kmalloc (ATAPI_MAX_DRAIN , q->bounce_gfp |GFP_KERNEL ); -if (!buf) { +/* make room for appending the drain */ +blk_queue_max_segments (q,queue_max_segments (q) -1 ); + + sdev->dma_drain_len =ATAPI_MAX_DRAIN ; + sdev->dma_drain_buf =kmalloc (sdev->dma_drain_len, + q->bounce_gfp |GFP_KERNEL ); +if (!sdev->dma_drain_buf) {ata_dev_err (dev,"drain buffer allocation failed\n" );return -ENOMEM ; } - -blk_queue_dma_drain (q, atapi_drain_needed, buf,ATAPI_MAX_DRAIN ); }else { sdev->sector_size =ata_id_logical_sector_size (dev->id); sdev->manage_start_stop =1 ;
@@ -1135,7 +1130,6 @@ EXPORT_SYMBOL_GPL(ata_scsi_slave_config);void ata_scsi_slave_destroy (struct scsi_device *sdev) {struct ata_port *ap =ata_shost_to_port (sdev->host); -struct request_queue *q = sdev->request_queue;unsigned long flags;struct ata_device *dev;
@@ -1152,9 +1146,7 @@ void ata_scsi_slave_destroy(struct scsi_device *sdev) }spin_unlock_irqrestore (ap->lock, flags); -kfree (q->dma_drain_buffer); - q->dma_drain_buffer =NULL ; - q->dma_drain_size =0 ; +kfree (sdev->dma_drain_buf); }EXPORT_SYMBOL_GPL (ata_scsi_slave_destroy);
drivers/scsi/scsi_lib.c +34 -5
@@ -978,6 +978,14 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)scsi_io_completion_action (cmd, result); } +static inline bool scsi_cmd_needs_dma_drain (struct scsi_device *sdev, +struct request *rq) +{ +return sdev->dma_drain_len &&blk_rq_is_passthrough (rq) && + !op_is_write (req_op (rq)) && + sdev->host->hostt->dma_need_drain (rq); +} +/* * Function: scsi_init_io() *
@@ -991,26 +999,47 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)*/ blk_status_t scsi_init_io (struct scsi_cmnd *cmd) { +struct scsi_device *sdev = cmd->device;struct request *rq = cmd->request; +unsigned short nr_segs =blk_rq_nr_phys_segments (rq); +struct scatterlist *last_sg =NULL ;blk_status_t ret; +bool need_drain =scsi_cmd_needs_dma_drain (sdev, rq);int count; -if (WARN_ON_ONCE (!blk_rq_nr_phys_segments (rq))) +if (WARN_ON_ONCE (!nr_segs))return BLK_STS_IOERR ; +/* +* Make sure there is space for the drain. The driver must adjust +* max_hw_segments to be prepared for this. +*/ +if (need_drain) + nr_segs++; +/* * If sg table allocation fails, requeue request later. */ -if (unlikely (sg_alloc_table_chained (&cmd->sdb.table, -blk_rq_nr_phys_segments (rq), cmd->sdb.table.sgl, -SCSI_INLINE_SG_CNT ))) +if (unlikely (sg_alloc_table_chained (&cmd->sdb.table, nr_segs, + cmd->sdb.table.sgl,SCSI_INLINE_SG_CNT )))return BLK_STS_RESOURCE ;/* * Next, walk the list, and fill in the addresses and sizes of * each segment. */ - count =blk_rq_map_sg (rq->q, rq, cmd->sdb.table.sgl); + count =__blk_rq_map_sg (rq->q, rq, cmd->sdb.table.sgl, &last_sg); + +if (need_drain) { +sg_unmark_end (last_sg); + last_sg =sg_next (last_sg); +sg_set_buf (last_sg, sdev->dma_drain_buf, sdev->dma_drain_len); +sg_mark_end (last_sg); + + rq->extra_len += sdev->dma_drain_len; + count++; + } +BUG_ON (count > cmd->sdb.table.nents); cmd->sdb.table.nents = count; cmd->sdb.length =blk_rq_payload_bytes (rq);
include/linux/blkdev.h +0 -7
@@ -288,7 +288,6 @@ struct blk_queue_ctx;typedef blk_qc_t (make_request_fn ) (struct request_queue *q,struct bio *bio);struct bio_vec ; -typedef int (dma_drain_needed_fn )(struct request *);enum blk_eh_timer_return {BLK_EH_DONE ,/* drivers has completed the command */
@@ -397,7 +396,6 @@ struct request_queue {struct rq_qos *rq_qos;make_request_fn *make_request_fn; -dma_drain_needed_fn *dma_drain_needed;const struct blk_mq_ops *mq_ops;
@@ -467,8 +465,6 @@ struct request_queue {*/ unsigned long nr_requests;/* Max # of requests */ -unsigned int dma_drain_size; -void *dma_drain_buffer;unsigned int dma_pad_mask;unsigned int dma_alignment;
@@ -1097,9 +1093,6 @@ extern void disk_stack_limits(struct gendisk *disk, struct block_device *bdev, sector_t offset);extern void blk_queue_stack_limits (struct request_queue *t,struct request_queue *b);extern void blk_queue_update_dma_pad (struct request_queue *,unsigned int ); -extern int blk_queue_dma_drain (struct request_queue *q, -dma_drain_needed_fn *dma_drain_needed, -void *buf,unsigned int size);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_dma_alignment (struct request_queue *,int );
include/linux/libata.h +2 -0
@@ -1092,6 +1092,7 @@ extern int ata_scsi_ioctl(struct scsi_device *dev, unsigned int cmd,#define ATA_SCSI_COMPAT_IOCTL /* empty */ #endif extern int ata_scsi_queuecmd (struct Scsi_Host *h,struct scsi_cmnd *cmd); +bool ata_scsi_dma_need_drain (struct request *rq);extern int ata_sas_scsi_ioctl (struct ata_port *ap,struct scsi_device *dev,unsigned int cmd,void __user *arg);extern bool ata_link_online (struct ata_link *link);
@@ -1387,6 +1388,7 @@ extern struct device_attribute *ata_common_sdev_attrs[]; .ioctl = ata_scsi_ioctl, \ATA_SCSI_COMPAT_IOCTL \ .queuecommand = ata_scsi_queuecmd, \ + .dma_need_drain = ata_scsi_dma_need_drain, \ .can_queue = ATA_DEF_QUEUE, \ .tag_alloc_policy = BLK_TAG_ALLOC_RR, \ .this_id = ATA_SHT_THIS_ID, \
include/scsi/scsi_device.h +3 -0
@@ -229,6 +229,9 @@ struct scsi_device {struct scsi_device_handler *handler;void *handler_data; +size_t dma_drain_len; +void *dma_drain_buf; +unsigned char access_state;struct mutex state_mutex;enum scsi_device_state sdev_state;
include/scsi/scsi_host.h +7 -0
@@ -270,6 +270,13 @@ struct scsi_host_template {*/ int (* map_queues)(struct Scsi_Host *shost); +/* +* Check if scatterlists need to be padded for DMA draining. +* +* Status: OPTIONAL +*/ +bool (* dma_need_drain)(struct request *rq); +/* * This function determines the BIOS parameters for a given * harddisk. These tend to be numbers that are made up by
Signature · 1 line
2.25.1
PATCH 5/5 block: move dma_pad handling from blk_rq_map_sg into the callers
In reply to Christoph HellwigThere are only two callers of blk_rq_map_sg/__blk_rq_map_sg that set the dma_pad value in the queue. Move the handling into those callers instead of burdening the common code, and move the ->extra_len field from struct request to struct scsi_cmnd.
--- block/blk-core.c | 1 - block/blk-merge.c | 8 -------- block/blk-mq.c | 1 - drivers/ata/libata-scsi.c | 2 +- drivers/ide/ide-io.c | 7 +++++-- drivers/scsi/scsi_lib.c | 10 +++++++++- include/linux/blkdev.h | 2 -- include/scsi/scsi_cmnd.h | 1 + 8 files changed, 16 insertions(+), 16 deletions(-)
block/blk-core.c +0 -1
@@ -1638,7 +1638,6 @@ int blk_rq_prep_clone(struct request *rq, struct request *rq_src, } rq->nr_phys_segments = rq_src->nr_phys_segments; rq->ioprio = rq_src->ioprio; - rq->extra_len = rq_src->extra_len;return 0 ;
block/blk-merge.c +0 -8
@@ -531,14 +531,6 @@ int __blk_rq_map_sg(struct request_queue *q, struct request *rq,else if (rq->bio) nsegs =__blk_bios_map_sg (q, rq->bio, sglist, last_sg); -if (blk_rq_bytes (rq) && (blk_rq_bytes (rq) & q->dma_pad_mask)) { -unsigned int pad_len = - (q->dma_pad_mask & ~blk_rq_bytes (rq)) +1 ; - - (*last_sg)->length += pad_len; - rq->extra_len += pad_len; - } -if (*last_sg)sg_mark_end (*last_sg);
block/blk-mq.c +0 -1
@@ -318,7 +318,6 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data, rq->nr_integrity_segments =0 ;#endif /* tag was already set */ - rq->extra_len =0 ;WRITE_ONCE (rq->deadline,0 ); rq->timeout =0 ;
drivers/ata/libata-scsi.c +1 -1
@@ -649,7 +649,7 @@ static void ata_qc_set_pc_nbytes(struct ata_queued_cmd *qc) {struct scsi_cmnd *scmd = qc->scsicmd; - qc->extrabytes = scmd->request->extra_len; + qc->extrabytes = scmd->extra_len; qc->nbytes =scsi_bufflen (scmd) + qc->extrabytes; }
drivers/ide/ide-io.c +5 -2
@@ -233,10 +233,13 @@ static ide_startstop_t do_special(ide_drive_t *drive)void ide_map_sg (ide_drive_t *drive,struct ide_cmd *cmd) {ide_hwif_t *hwif = drive->hwif; -struct scatterlist *sg = hwif->sg_table; +struct scatterlist *sg = hwif->sg_table, *last_sg =NULL ;struct request *rq = cmd->rq; - cmd->sg_nents =blk_rq_map_sg (drive->queue, rq, sg); + cmd->sg_nents =__blk_rq_map_sg (drive->queue, rq, sg, &last_sg); +if (blk_rq_bytes (rq) && (blk_rq_bytes (rq) & rq->q->dma_pad_mask)) + last_sg->length += + (rq->q->dma_pad_mask & ~blk_rq_bytes (rq)) +1 ; }EXPORT_SYMBOL_GPL (ide_map_sg);
drivers/scsi/scsi_lib.c +9 -1
@@ -1030,13 +1030,21 @@ blk_status_t scsi_init_io(struct scsi_cmnd *cmd)*/ count =__blk_rq_map_sg (rq->q, rq, cmd->sdb.table.sgl, &last_sg); +if (blk_rq_bytes (rq) & rq->q->dma_pad_mask) { +unsigned int pad_len = + (rq->q->dma_pad_mask & ~blk_rq_bytes (rq)) +1 ; + + last_sg->length += pad_len; + cmd->extra_len += pad_len; + } +if (need_drain) {sg_unmark_end (last_sg); last_sg =sg_next (last_sg);sg_set_buf (last_sg, sdev->dma_drain_buf, sdev->dma_drain_len);sg_mark_end (last_sg); - rq->extra_len += sdev->dma_drain_len; + cmd->extra_len += sdev->dma_drain_len; count++; }
include/linux/blkdev.h +0 -2
@@ -224,8 +224,6 @@ struct request {unsigned short write_hint;unsigned short ioprio; -unsigned int extra_len;/* length of alignment and padding */ -enum mq_rq_state state;refcount_t ref;
include/scsi/scsi_cmnd.h +1 -0
@@ -142,6 +142,7 @@ struct scsi_cmnd {unsigned long state;/* Command completion state */ unsigned char tag;/* SCSI-II queued command tag */ +unsigned int extra_len;/* length of alignment and padding */ };/*
Signature · 1 line
2.25.1
Quoted 5 lines · Christoph Hellwig
Hi all,
currently the dma draining and alignining specific to ATA CDROMs and the UFS driver has its ugly hooks in core block code. Move this out into the scsi and ide drivers instead.
Any commens?
Jens Axboe
maintainerQuoted 8 lines · Christoph Hellwig
Quoted 5 lines · Christoph Hellwig
Hi all,
currently the dma draining and alignining specific to ATA CDROMs and the UFS driver has its ugly hooks in core block code. Move this out into the scsi and ide drivers instead.
Any commens?
Looks OK to me, and I think the idea is sound.
Signature · 1 line
Jens Axboe