All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org,
	Jaegeuk Kim <jaegeuk@kernel.org>,
	Avri Altman <avri.altman@wdc.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Christoph Hellwig <hch@lst.de>, Ming Lei <ming.lei@redhat.com>,
	Bart Van Assche <bvanassche@acm.org>,
	Keith Busch <kbusch@kernel.org>
Subject: [PATCH v4 5/7] block: Add support for small segments in blk_rq_map_user_iov()
Date: Mon, 30 Jan 2023 13:26:54 -0800	[thread overview]
Message-ID: <20230130212656.876311-6-bvanassche@acm.org> (raw)
In-Reply-To: <20230130212656.876311-1-bvanassche@acm.org>

Before changing the return value of bio_add_hw_page() into a value in
the range [0, len], make blk_rq_map_user_iov() fall back to copying data
if mapping the data is not possible due to the segment limit.

Cc: Christoph Hellwig <hch@lst.de>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Keith Busch <kbusch@kernel.org>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 block/blk-map.c | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/block/blk-map.c b/block/blk-map.c
index eb059d3a1be2..b1dad4690472 100644
--- a/block/blk-map.c
+++ b/block/blk-map.c
@@ -307,17 +307,26 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter,
 		else {
 			for (j = 0; j < npages; j++) {
 				struct page *page = pages[j];
-				unsigned int n = PAGE_SIZE - offs;
+				unsigned int n = PAGE_SIZE - offs, added;
 				bool same_page = false;
 
 				if (n > bytes)
 					n = bytes;
 
-				if (!bio_add_hw_page(rq->q, bio, page, n, offs,
-						     max_sectors, &same_page)) {
+				added = bio_add_hw_page(rq->q, bio, page, n,
+						offs, max_sectors, &same_page);
+				if (added == 0) {
 					if (same_page)
 						put_page(page);
 					break;
+				} else if (added != n) {
+					/*
+					 * The segment size is smaller than the
+					 * page size and an iov exceeds the
+					 * segment size. Give up.
+					 */
+					ret = -EREMOTEIO;
+					goto out_unmap;
 				}
 
 				bytes -= n;
@@ -657,10 +666,18 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq,
 
 	i = *iter;
 	do {
-		if (copy)
+		if (copy) {
 			ret = bio_copy_user_iov(rq, map_data, &i, gfp_mask);
-		else
+		} else {
 			ret = bio_map_user_iov(rq, &i, gfp_mask);
+			/*
+			 * Fall back to copying the data if bio_map_user_iov()
+			 * returns -EREMOTEIO.
+			 */
+			if (ret == -EREMOTEIO)
+				ret = bio_copy_user_iov(rq, map_data, &i,
+							gfp_mask);
+		}
 		if (ret)
 			goto unmap_rq;
 		if (!bio)

  parent reply	other threads:[~2023-01-30 21:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-30 21:26 [PATCH v4 0/7] Add support for limits below the page size Bart Van Assche
2023-01-30 21:26 ` [PATCH v4 1/7] block: Introduce blk_mq_debugfs_init() Bart Van Assche
2023-02-01 20:58   ` Luis Chamberlain
2023-02-01 21:23     ` Luis Chamberlain
2023-02-01 22:01       ` Bart Van Assche
2023-02-01 23:59         ` Luis Chamberlain
2023-02-02  1:06           ` Bart Van Assche
2023-02-06 16:03             ` Luis Chamberlain
2023-02-06 21:11               ` Bart Van Assche
2023-01-30 21:26 ` [PATCH v4 2/7] block: Support configuring limits below the page size Bart Van Assche
2023-02-01 23:50   ` Luis Chamberlain
2023-02-07  0:02     ` Bart Van Assche
2023-02-07  0:19       ` Luis Chamberlain
2023-02-07  0:31         ` Bart Van Assche
2023-02-07  2:08           ` Luis Chamberlain
2023-02-07 18:26             ` Bart Van Assche
2023-01-30 21:26 ` [PATCH v4 3/7] block: Support submitting passthrough requests with small segments Bart Van Assche
2023-01-30 21:26 ` [PATCH v4 4/7] block: Add support for filesystem requests and " Bart Van Assche
2023-01-30 21:26 ` Bart Van Assche [this message]
2023-01-30 21:26 ` [PATCH v4 6/7] scsi_debug: Support configuring the maximum segment size Bart Van Assche
2023-01-30 21:26 ` [PATCH v4 7/7] null_blk: " Bart Van Assche

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230130212656.876311-6-bvanassche@acm.org \
    --to=bvanassche@acm.org \
    --cc=adrian.hunter@intel.com \
    --cc=avri.altman@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=jaegeuk@kernel.org \
    --cc=kbusch@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.