Re: [PATCH v2 05/21] Add a function to kmap one page of a multipage bio_vec
From: Christoph Hellwig
Date: Mon May 25 2026 - 02:13:38 EST
On Mon, May 18, 2026 at 11:29:37PM +0100, David Howells wrote:
> 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 <dhowells@xxxxxxxxxx>
> Acked-by: Paulo Alcantara (Red Hat) <pc@xxxxxxxxxxxxx>
> cc: Matthew Wilcox <willy@xxxxxxxxxxxxx>
> cc: Christoph Hellwig <hch@xxxxxxxxxxxxx>
> cc: Jens Axboe <axboe@xxxxxxxxx>
> cc: linux-block@xxxxxxxxxxxxxxx
> cc: netfs@xxxxxxxxxxxxxxx
> cc: linux-fsdevel@xxxxxxxxxxxxxxx
> ---
> include/linux/bvec.h | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/include/linux/bvec.h b/include/linux/bvec.h
> index d36dd476feda..9df4a56fef61 100644
> --- a/include/linux/bvec.h
> +++ b/include/linux/bvec.h
> @@ -299,4 +299,21 @@ static inline phys_addr_t bvec_phys(const struct bio_vec *bvec)
> return page_to_phys(bvec->bv_page) + bvec->bv_offset;
> }
>
> +/**
> + * kmap_local_bvec - 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 *kmap_local_bvec(struct bio_vec *bvec, size_t offset)
The name is rather confusing for something that does not map the entire
bvec, and is an anagram of the existing bvec_kmap_local. So please
rename it to bvec_kmap_partial or something.
> +{
> + offset += bvec->bv_offset;
> +
> + return kmap_local_page(bvec->bv_page + offset / PAGE_SIZE) + offset % PAGE_SIZE;
Overly long line. Also this can use shits and byte masking to be a tad
more efficient and matching the rest of the bvec code.
Users of this would be interesting and why you're not simply using a
bvec_iter at page granularity, which is what other block kmap code
does.