Skip to content

Commit 7f8851d

Browse files
committed
Merge branch 'for-6.11/block' into for-next
* for-6.11/block: block: pass a phys_addr_t to get_max_segment_size block: add a bvec_phys helper
2 parents 0d32bc0 + 09595e0 commit 7f8851d

File tree

5 files changed

+29
-18
lines changed

5 files changed

+29
-18
lines changed

arch/m68k/emu/nfblock.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static void nfhd_submit_bio(struct bio *bio)
7171
len = bvec.bv_len;
7272
len >>= 9;
7373
nfhd_read_write(dev->id, 0, dir, sec >> shift, len >> shift,
74-
page_to_phys(bvec.bv_page) + bvec.bv_offset);
74+
bvec_phys(&bvec));
7575
sec += len;
7676
}
7777
bio_endio(bio);

block/bio.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ bool bvec_try_merge_hw_page(struct request_queue *q, struct bio_vec *bv,
953953
bool *same_page)
954954
{
955955
unsigned long mask = queue_segment_boundary(q);
956-
phys_addr_t addr1 = page_to_phys(bv->bv_page) + bv->bv_offset;
956+
phys_addr_t addr1 = bvec_phys(bv);
957957
phys_addr_t addr2 = page_to_phys(page) + offset + len - 1;
958958

959959
if ((addr1 | mask) != (addr2 | mask))

block/blk-merge.c

+11-14
Original file line numberDiff line numberDiff line change
@@ -209,23 +209,22 @@ static inline unsigned get_max_io_size(struct bio *bio,
209209
/**
210210
* get_max_segment_size() - maximum number of bytes to add as a single segment
211211
* @lim: Request queue limits.
212-
* @start_page: See below.
213-
* @offset: Offset from @start_page where to add a segment.
212+
* @paddr: address of the range to add
213+
* @max_len: maximum length available to add at @paddr
214214
*
215-
* Returns the maximum number of bytes that can be added as a single segment.
215+
* Returns the maximum number of bytes of the range starting at @paddr that can
216+
* be added to a single segment.
216217
*/
217218
static inline unsigned get_max_segment_size(const struct queue_limits *lim,
218-
struct page *start_page, unsigned long offset)
219+
phys_addr_t paddr, unsigned int len)
219220
{
220-
unsigned long mask = lim->seg_boundary_mask;
221-
222-
offset = mask & (page_to_phys(start_page) + offset);
223-
224221
/*
225222
* Prevent an overflow if mask = ULONG_MAX and offset = 0 by adding 1
226223
* after having calculated the minimum.
227224
*/
228-
return min(mask - offset, (unsigned long)lim->max_segment_size - 1) + 1;
225+
return min_t(unsigned long, len,
226+
min(lim->seg_boundary_mask - (lim->seg_boundary_mask & paddr),
227+
(unsigned long)lim->max_segment_size - 1) + 1);
229228
}
230229

231230
/**
@@ -258,9 +257,7 @@ static bool bvec_split_segs(const struct queue_limits *lim,
258257
unsigned seg_size = 0;
259258

260259
while (len && *nsegs < max_segs) {
261-
seg_size = get_max_segment_size(lim, bv->bv_page,
262-
bv->bv_offset + total_len);
263-
seg_size = min(seg_size, len);
260+
seg_size = get_max_segment_size(lim, bvec_phys(bv) + total_len, len);
264261

265262
(*nsegs)++;
266263
total_len += seg_size;
@@ -494,8 +491,8 @@ static unsigned blk_bvec_map_sg(struct request_queue *q,
494491

495492
while (nbytes > 0) {
496493
unsigned offset = bvec->bv_offset + total;
497-
unsigned len = min(get_max_segment_size(&q->limits,
498-
bvec->bv_page, offset), nbytes);
494+
unsigned len = get_max_segment_size(&q->limits, bvec_phys(bvec),
495+
nbytes);
499496
struct page *page = bvec->bv_page;
500497

501498
/*

block/blk.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ static inline bool biovec_phys_mergeable(struct request_queue *q,
9999
struct bio_vec *vec1, struct bio_vec *vec2)
100100
{
101101
unsigned long mask = queue_segment_boundary(q);
102-
phys_addr_t addr1 = page_to_phys(vec1->bv_page) + vec1->bv_offset;
103-
phys_addr_t addr2 = page_to_phys(vec2->bv_page) + vec2->bv_offset;
102+
phys_addr_t addr1 = bvec_phys(vec1);
103+
phys_addr_t addr2 = bvec_phys(vec2);
104104

105105
/*
106106
* Merging adjacent physical pages may not work correctly under KMSAN

include/linux/bvec.h

+14
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,18 @@ static inline void *bvec_virt(struct bio_vec *bvec)
280280
return page_address(bvec->bv_page) + bvec->bv_offset;
281281
}
282282

283+
/**
284+
* bvec_phys - return the physical address for a bvec
285+
* @bvec: bvec to return the physical address for
286+
*/
287+
static inline phys_addr_t bvec_phys(const struct bio_vec *bvec)
288+
{
289+
/*
290+
* Note this open codes page_to_phys because page_to_phys is defined in
291+
* <asm/io.h>, which we don't want to pull in here. If it ever moves to
292+
* a sensible place we should start using it.
293+
*/
294+
return PFN_PHYS(page_to_pfn(bvec->bv_page)) + bvec->bv_offset;
295+
}
296+
283297
#endif /* __LINUX_BVEC_H */

0 commit comments

Comments
 (0)