]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
block: add a bvec_phys helper
authorChristoph Hellwig <hch@lst.de>
Sat, 6 Jul 2024 07:52:17 +0000 (09:52 +0200)
committerJens Axboe <axboe@kernel.dk>
Mon, 8 Jul 2024 07:51:05 +0000 (01:51 -0600)
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 <hch@lst.de>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Link: https://lore.kernel.org/r/20240706075228.2350978-2-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
arch/m68k/emu/nfblock.c
block/bio.c
block/blk.h
include/linux/bvec.h

index 8eea7ef9115146a37928754b8ca9cdc5297add5a..874fe958877388addde6a80c2662dae5b5e62fad 100644 (file)
@@ -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);
index e9e809a63c5975183dc710452e6cac612d1a67af..a3b1b2266c50be61df263cb713e3726b1fa5295d 100644 (file)
@@ -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))
index 47dadd2439b1ca97f2f2c3eea8b99ca261ecd05b..8e8936e97307c620fe785547b20ea3263655c90e 100644 (file)
@@ -98,8 +98,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
index bd1e361b351c5afa88ff02e7023cd79acd5454fd..f41c7f0ef91ed53fefec87a1274ef205576ba5ad 100644 (file)
@@ -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 */