Re: [PATCH v9 04/26] Add a function to kmap one page of a multipage bio_vec

Matthew Wilcox <[email protected]>
Newsgroups gmane.linux.block,gmane.linux.kernel.cifs,gmane.linux.nfs,gmane.comp.file-systems.ceph.devel,gmane.linux.file-systems,gmane.linux.kernel
Message-ID <[email protected]>
On Mon, Aug 10, 2026 at 03:47:21PM +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.

I think this should be kmap_local_bvec().  Living in bvec.h makes sense,
but keeping it in the kmap_local_ namespace is better than putting it in
the bvec_ namespace.

The bvec should be const-qualified.  We're not very good at
being const-clean, but let's try harder ;-)

I think it's better to steal the same terminology for the kernel-doc
used in highmem.h, just for consistency:

/**
 * kmap_local_bvec - Map a page in this bvec for temporary usage
 * @bvec: The bvec containing the page.
 * @offset: The first byte within the bvec to map.
 *
 * This will not map the entire bvec, only the page containing @offset
 * from the start of @bvec.  Unmap the address with kunmap_local().
 * See kmap_local_page() for nesting rules.
 *
 * Context: Interrupt or process context.
 * Return: A pointer to a temporary mapping.
 */

> +/**
> + * 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 */
> 
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.