Skip to content

Commit 25f76c3

Browse files
Christoph Hellwigaxboe
Christoph Hellwig
authored andcommitted
block: add a bvec_phys helper
Get callers out of poking into bvec internals a bit more. Not a huge win right now, but with the proposed new DMA mapping API we might end up with a lot more of this otherwise. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent bf86bcd commit 25f76c3

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
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.h

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

104104
/*
105105
* 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)