Skip to content

Commit

Permalink
Merge branch 'for-6.11/block' into for-next
Browse files Browse the repository at this point in the history
* for-6.11/block:
  block: pass a phys_addr_t to get_max_segment_size
  block: add a bvec_phys helper
  • Loading branch information
axboe committed Jul 8, 2024
2 parents 0d32bc0 + 09595e0 commit 7f8851d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion arch/m68k/emu/nfblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static void nfhd_submit_bio(struct bio *bio)
len = bvec.bv_len;
len >>= 9;
nfhd_read_write(dev->id, 0, dir, sec >> shift, len >> shift,
page_to_phys(bvec.bv_page) + bvec.bv_offset);
bvec_phys(&bvec));
sec += len;
}
bio_endio(bio);
Expand Down
2 changes: 1 addition & 1 deletion block/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ bool bvec_try_merge_hw_page(struct request_queue *q, struct bio_vec *bv,
bool *same_page)
{
unsigned long mask = queue_segment_boundary(q);
phys_addr_t addr1 = page_to_phys(bv->bv_page) + bv->bv_offset;
phys_addr_t addr1 = bvec_phys(bv);
phys_addr_t addr2 = page_to_phys(page) + offset + len - 1;

if ((addr1 | mask) != (addr2 | mask))
Expand Down
25 changes: 11 additions & 14 deletions block/blk-merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,23 +209,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
* @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
* @max_len: maximum length available to add at @paddr
*
* 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 @paddr that can
* be added to a single segment.
*/
static inline unsigned get_max_segment_size(const struct queue_limits *lim,
struct page *start_page, unsigned long offset)
phys_addr_t paddr, unsigned int len)
{
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_t(unsigned long, len,
min(lim->seg_boundary_mask - (lim->seg_boundary_mask & paddr),
(unsigned long)lim->max_segment_size - 1) + 1);
}

/**
Expand Down Expand Up @@ -258,9 +257,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,
bv->bv_offset + total_len);
seg_size = min(seg_size, len);
seg_size = get_max_segment_size(lim, bvec_phys(bv) + total_len, len);

(*nsegs)++;
total_len += seg_size;
Expand Down Expand Up @@ -494,8 +491,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);
unsigned len = get_max_segment_size(&q->limits, bvec_phys(bvec),
nbytes);
struct page *page = bvec->bv_page;

/*
Expand Down
4 changes: 2 additions & 2 deletions block/blk.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ static inline bool biovec_phys_mergeable(struct request_queue *q,
struct bio_vec *vec1, struct bio_vec *vec2)
{
unsigned long mask = queue_segment_boundary(q);
phys_addr_t addr1 = page_to_phys(vec1->bv_page) + vec1->bv_offset;
phys_addr_t addr2 = page_to_phys(vec2->bv_page) + vec2->bv_offset;
phys_addr_t addr1 = bvec_phys(vec1);
phys_addr_t addr2 = bvec_phys(vec2);

/*
* Merging adjacent physical pages may not work correctly under KMSAN
Expand Down
14 changes: 14 additions & 0 deletions include/linux/bvec.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,18 @@ static inline void *bvec_virt(struct bio_vec *bvec)
return page_address(bvec->bv_page) + bvec->bv_offset;
}

/**
* bvec_phys - return the physical address for a bvec
* @bvec: bvec to return the physical address for
*/
static inline phys_addr_t bvec_phys(const struct bio_vec *bvec)
{
/*
* Note this open codes page_to_phys because page_to_phys is defined in
* <asm/io.h>, which we don't want to pull in here. If it ever moves to
* a sensible place we should start using it.
*/
return PFN_PHYS(page_to_pfn(bvec->bv_page)) + bvec->bv_offset;
}

#endif /* __LINUX_BVEC_H */

0 comments on commit 7f8851d

Please sign in to comment.