[Devel] [PATCH hci-8.1] fs/fuse kio: build the rdma sgl from folios

Konstantin Khorenko khorenko at virtuozzo.com
Wed Nov 18 13:33:32 MSK 2026


I won't apply this version, please send v2 with the changes below.

- Take only bvec iterators: for anything else return before the
  allocation, so the caller falls back to the copy path.
- Count the extra entries per segment longer than max_seg, without the
  "len > it.nr_segs * PAGE_SIZE" shortcut.
- Fix the comments that say "one entry per folio" and "we can't
  undercount".
- Message: Fixes: ed62e3c51fa2 ("fs/fuse kio: teach pcs_umem about
  hugepage-backed mappings") instead of "the umem hugepage work", and
  "Feature: vStorage" as the other pcs commits have.

On Wed, 18 Nov 2026 13:01:15 +0800, Liu Kui wrote:
> +		/* a segment never spans folios */
> +		len = iov_iter_single_seg_count(&it);
>  		if (len > end_offset - msg_offset)
>  			len = end_offset - msg_offset;
>  
> -		sg_set_page(sg, sbuf->pages[sbuf->pg_cnt++], len, off);
> +		/* find the page under the current position, no reference is taken */
> +		got = iov_iter_extract_pages(&it, &pp, 1, 1, 0, &off);

This holds for the bvec builders, not for ITER_KVEC, which
iov_iter_extract_pages() accepts. A CS FIEMAP reply read over RDMA
goes rio_submit_rdma_read() -> pcs_rdma_rw_init_from_msg() ->
fiemap_get_iter(), a kvec over the kvmalloc(PCS_FIEMAP_BUFSIZE)
buffer. When kvmalloc() falls back to vmalloc, the extraction returns
the first page only, sg_set_folio() describes the whole reply as
physically contiguous from it, and the RDMA read writes into whatever
pages follow. The old code did not handle kvec either (the -EFAULT of
iov_iter_get_pages2() went into a size_t), but it crashed; now the
memory is silently corrupted.

> +		if (len > it.nr_segs * PAGE_SIZE && unlikely(len > max_seg))
> +			sbuf->sg_cnt += DIV_ROUND_UP(len, max_seg);

The check compares the total length, so one long segment among many
short ones is missed: with the 64K default max_seg, one 96K hugepage
segment plus enough short segments allocates one entry too few, the
fill loop hits WARN_ON_ONCE() (a panic with panic_on_warn) and falls
back. "if (len > max_seg) sg_cnt += len / max_seg" is a true upper
bound.

Thanks.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team



More information about the Devel mailing list