[PATCH v7 09/29] Add a function to kmap one page of a multipage bio_vec
David Howells <[email protected]> Wed, 22 Jul 2026 14:01:56 +0100
| Newsgroups | dev.linux.lists.v9fs,dev.linux.lists.netfs,org.kernel.vger.ceph-devel,org.kernel.vger.linux-block,org.kernel.vger.linux-cifs,org.kernel.vger.linux-fsdevel,org.kernel.vger.linux-kernel,org.kernel.vger.linux-nfs,org.ozlabs.lists.linux-erofs |
|---|---|
| Message-ID | <[email protected]> |
Add a function to kmap one page of a multipage bio_vec by offset (which is added to the offset in the bio_vec internally). The caller is responsible for calculating how much of the page is then available. Signed-off-by: David Howells <[email protected]> Acked-by: Paulo Alcantara (Red Hat) <[email protected]> cc: Matthew Wilcox <[email protected]> cc: Christoph Hellwig <[email protected]> cc: Jens Axboe <[email protected]> cc: [email protected] cc: [email protected] cc: [email protected] --- include/linux/bvec.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/linux/bvec.h b/include/linux/bvec.h index 92837e2743f1..53cf36e73967 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -343,4 +343,22 @@ static inline phys_addr_t bvec_phys(const struct bio_vec *bvec) return page_to_phys(bvec->bv_page) + bvec->bv_offset; } +/** + * bvec_kmap_partial - Map part of a bvec into the kernel virtual address space + * @bvec: bvec to map + * @offset: Offset into bvec + * + * Map the page containing the byte at @offset into the kernel virtual address + * space. The caller is responsible for making sure this doesn't overrun. + * + * Call kunmap_local on the returned address to unmap. + */ +static inline void *bvec_kmap_partial(struct bio_vec *bvec, size_t offset) +{ + offset += bvec->bv_offset; + + return kmap_local_page(bvec->bv_page + (offset >> PAGE_SHIFT)) + + (offset & ~PAGE_MASK); +} + #endif /* __LINUX_BVEC_H */