public inbox for linux-m68k@lists.linux-m68k.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>,
	linux-m68k@lists.linux-m68k.org, linux-block@vger.kernel.org
Subject: [PATCH 1/2] block: pass a phys_addr_t to get_max_segment_size
Date: Fri,  5 Jul 2024 10:14:33 +0200	[thread overview]
Message-ID: <20240705081508.2110169-2-hch@lst.de> (raw)
In-Reply-To: <20240705081508.2110169-1-hch@lst.de>

Work on a single address to simplify the logic, and prepare the callers
from using better helpers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/blk-merge.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/block/blk-merge.c b/block/blk-merge.c
index cff20bcc0252a7..515173342eb757 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -207,25 +207,22 @@ static inline unsigned get_max_io_size(struct bio *bio,
 }
 
 /**
- * get_max_segment_size() - maximum number of bytes to add as a single segment
+ * get_max_segment_size() - maximum number of bytes to add to a single segment
  * @lim: Request queue limits.
- * @start_page: See below.
- * @offset: Offset from @start_page where to add a segment.
+ * @paddr: address of the range to add
  *
- * Returns the maximum number of bytes that can be added as a single segment.
+ * Returns the maximum number of bytes of the range starting at @addr that can
+ * be added to a single request.
  */
 static inline unsigned get_max_segment_size(const struct queue_limits *lim,
-		struct page *start_page, unsigned long offset)
+		phys_addr_t paddr)
 {
-	unsigned long mask = lim->seg_boundary_mask;
-
-	offset = mask & (page_to_phys(start_page) + offset);
-
 	/*
 	 * Prevent an overflow if mask = ULONG_MAX and offset = 0 by adding 1
 	 * after having calculated the minimum.
 	 */
-	return min(mask - offset, (unsigned long)lim->max_segment_size - 1) + 1;
+	return min(lim->seg_boundary_mask - (lim->seg_boundary_mask & paddr),
+		    (unsigned long)lim->max_segment_size - 1) + 1;
 }
 
 /**
@@ -258,7 +255,7 @@ static bool bvec_split_segs(const struct queue_limits *lim,
 	unsigned seg_size = 0;
 
 	while (len && *nsegs < max_segs) {
-		seg_size = get_max_segment_size(lim, bv->bv_page,
+		seg_size = get_max_segment_size(lim, page_to_phys(bv->bv_page) +
 						bv->bv_offset + total_len);
 		seg_size = min(seg_size, len);
 
@@ -495,7 +492,8 @@ static unsigned blk_bvec_map_sg(struct request_queue *q,
 	while (nbytes > 0) {
 		unsigned offset = bvec->bv_offset + total;
 		unsigned len = min(get_max_segment_size(&q->limits,
-				   bvec->bv_page, offset), nbytes);
+				   page_to_phys(bvec->bv_page) + offset),
+				   nbytes);
 		struct page *page = bvec->bv_page;
 
 		/*
-- 
2.43.0


  reply	other threads:[~2024-07-05  8:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-05  8:14 add a bvec_phys helper Christoph Hellwig
2024-07-05  8:14 ` Christoph Hellwig [this message]
2024-07-05  8:41   ` [PATCH 1/2] block: pass a phys_addr_t to get_max_segment_size Geert Uytterhoeven
2024-07-05  8:14 ` [PATCH 2/2] block: add a bvec_phys helper Christoph Hellwig
2024-07-05  8:50   ` Geert Uytterhoeven
2024-07-05 11:22     ` Christoph Hellwig
2024-07-05 11:30       ` Geert Uytterhoeven

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=20240705081508.2110169-2-hch@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=geert@linux-m68k.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-m68k@lists.linux-m68k.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox