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

no-reply at sashiko.virtuozzo.com no-reply at sashiko.virtuozzo.com
Wed Nov 18 19:16:33 MSK 2026


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] fuse kio: pcs_sgl_buf_init_from_msg() sizes the sgl by the whole
  remaining iterator
--

commit bf611f05472805568665b417b7285a66d56f26a0
Author: Liu Kui <kui.liu at virtuozzo.com>

fs/fuse kio: build the rdma sgl from folios

This commit switches pcs_sgl_buf_init_from_msg() and the related sgl helpers to build the scatterlist from folios. This way a bio_vec segment over a hugepage-backed buffer no longer overruns a scatterlist sized by segment count.

> diff --git a/fs/fuse/kio/pcs/pcs_rdma_rw.c b/fs/fuse/kio/pcs/pcs_rdma_rw.c
> --- a/fs/fuse/kio/pcs/pcs_rdma_rw.c
> +++ b/fs/fuse/kio/pcs/pcs_rdma_rw.c

[ ... ]

> +	/* count the entries, one per segment unless a segment is longer than max_seg */
> +	sbuf->sg_cnt = 0;
> +	msg_offset = offset;
> +	while (msg_offset < end_offset) {
> +		msg->get_iter(msg, msg_offset, &it, dir);
> +
> +		/* a kvec may be over vmalloc memory, leave it to the MR fallback */
> +		if (iov_iter_is_kvec(&it))
> +			return -EINVAL;
> +
> +		len = iov_iter_count(&it);
> +		if (len > end_offset - msg_offset)
> +			len = end_offset - msg_offset;
> +
> +		/* may overcount here, which is rare and harmless */
> +		sbuf->sg_cnt += it.nr_segs;

[Severity: Low]
Is the overcount here really rare? it.nr_segs is the number of segments left in the whole iterator, not the number inside [msg_offset, msg_offset + len). The get_iter() callbacks only truncate the byte count: req_get_iter() builds iov_iter_bvec() over all of r->exec.io.num_bvecs, and cs_get_read_response_iter() then calls iov_iter_truncate(), which leaves nr_segs alone.

So when fuse_io.c splits a request into chunks, each chunk is sized for every bvec left in the request. For a 1MB request with 256 bvecs, a chunk covering a quarter of it gets about 256 sg entries instead of about 64. That is an 8KB GFP_NOIO kzalloc plus memset on the RDMA read path, where the old code sized the list exactly.

It is bounded and transient, with no memory-safety impact, since sg_cnt is trimmed to cnt and the list is closed with sg_mark_end(). But the "rare and harmless" comment is inaccurate for split requests. Could the count be limited to the bvecs that cover len, for example by walking the segments against len?

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply at sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261118-b4-vstor-155302-sgl-folio-v2-1-bc5e45a53792@virtuozzo.com?part=1



More information about the Devel mailing list