From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 8FF86803F6 for ; Wed, 18 Nov 2026 15:58:59 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AIFvYIK026763; Wed, 18 Nov 2026 18:57:35 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AIFvYIK026763 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="pUCXmsF6" Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AIFvWrx026759 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 18 Nov 2026 18:57:33 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AIFvWrx026759 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-4a3705ea6ccso208858f8f.2 for ; Wed, 18 Nov 2026 07:57:32 -0800 (PST) X-Gm-Message-State: APuU4Z8rPqO6MWOlOMeSAaLFCnsFT+7wIKci4zXHidRMdQYF/QzPFyGv 6EBsbWC/r67owCaJCrfQn4JyfOkYpdEsn6kxClcsPT0XtOxjwOqrrnt46xBtWg+lA1hCLp0/BKa 0bHDykwfovDjDS7UZbeJF1ODvpbCzHMGalBwufI4Qa+7WdypeZX5DxA== X-Gm-Gg: AZFdTZdaMWlOAg6/MoTwEfgFvNBhBf/2buRjWZQ2KsPDN/8OYF8aKVLpNeDkkxxjAkq QUK1W85GJ8spPXRelVvMIZlYM8KSZqcpgHGDIgzv+2fI5cR7dQOrIxwwWwriegOowwVGVkrce/7 RJRiIqBuIG4XF4Kp8ZPO35e37iYDErBIeEr2NPz3CLG/N3CIdX7bp9DTGpL0LpnmbyfOTDIUr3u +oOwjxiW3Ktw6VO1mQiB9kJbCbh+8uswRmtfYy8Pq8ycdggNA59oXEKrTy6Oqy4mYwtZvKxWhx9 AGtIW5pnTpJ6BBQwORQ8DpdarFiop+wErMS5z/FHO/aJzrDt0Sitf/xKdbdI1/pge37ADUVadti h4YWq/Dn/EBRozKI= X-Received: by 2002:adf:e006:0:20b0:492:b5e9:4916 with SMTP id ffacd0b85a97d-4a63a4c0302mr4834540f8f.24.1795017452223; Wed, 18 Nov 2026 07:57:32 -0800 (PST) X-Received: by 2002:adf:e006:0:20b0:492:b5e9:4916 with SMTP id ffacd0b85a97d-4a63a4c0302mr4834492f8f.24.1795017451598; Wed, 18 Nov 2026 07:57:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795017451; cv=none; d=google.com; s=arc-20260327; b=sMsIRCuJUJ2tU0NI3MyS3R7HwH2L68FGS+9920okesZ9brApdoAOrzmHwel9hm9mXS B9+ZxAWQEssu/KKVxAbHdGE7CJuNPcT+xubsozKtlZncBy8dBNgcZF3PTeWvP9LWZttz rrYahoXibvDZNmrTLdM0j+bIOLl8UuFjAJpWJ7WNlGBDbEUgbzh++kSGfBTDdrl3spLE qF2+rYDL66NguMLdbbqZvPD7NE1zqO4LQA5h7JQG7J66yitUs30TZ5VxVJ4M18ckLmTy 90aeD+1YffrxCDCtwbi13ExpL7CFl5mBiqvO/3gT1R7jV9X+W1hayAHkublyw+NF6KHN o0GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:dkim-signature; bh=gqxhkjTMFLKJaDWKAQV5xjQoG5PmwigeT22nJRxK0CY=; fh=6JpqpGxFeFNaDh+k4t2UfZyo3rKe/54dyQ52T8vVmSc=; b=bYncfRdEFPNbAA/xQnRZo0Qjj8XL51PMu7Cyuw8R9UjCnlFudP30UN1rcyVVjdNriN vXU+GFyk1w78yw8/RUMu/EOgEVXLj0QCtE1bAwqLlqqpflmg4tQHR2zJgx8rdc3J/caC zgQSWDTQsBivaYRGRYQfJIDDR/0x72lUzcXj3NcJ6j6yNjnFaTXW05bPtFWC/6L8bHdg Hsq260vUrTlT3596b80bKlAtWhN2Tcq5HCvqlhe5ei4xqlDBswTIqh2qLUdDwXp9O2x6 /D8lOAgoTQ+XbU5fsJJb5t6wE95ub5t38wdnWEPgCGJ3q+p4anZi/BuzSAUV7+6b9CyQ SGPg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=pUCXmsF6; spf=pass (google.com: domain of kui.liu@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=kui.liu@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-4a6575a620csi5169574f8f.77.2026.11.18.07.57.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 07:57:31 -0800 (PST) Received-SPF: pass (google.com: domain of kui.liu@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=pUCXmsF6; spf=pass (google.com: domain of kui.liu@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=kui.liu@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Message-Id:Content-Type:MIME-Version:Subject:Date :From; bh=gqxhkjTMFLKJaDWKAQV5xjQoG5PmwigeT22nJRxK0CY=; b=pUCXmsF6c9CItsQl8h9 g1ZugjLeCHB2f5vEPr3YnUm7YJ8paU0JOYRKggGPTw+0WSauBYEc2o0zByzEssXsa33ZhRDQBnPeH 9PseU3TLbIkXs0u7PINTM8YOD5vqFEgUxZwj8pdE14VcxJj6eYs9ZbSsy9eYb1SGF9NIu3jA1kf/d D7//a+wKWImu/mBREutMf8/K3lwY4Snnu/sioJ8VWm17/AAh3ki1/+0L2vCw2JXDe3hWcCAFxiCTU +CsVvaRcs96jHFnYGwmCAW4TEmfvooOw4/nFoWcA66hrinn5O+QNfNjIPb7GV3HDsns9cDaRUoNme KKTFURQZfDDGShg==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=LK-MBP.local) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xThy4-007yiB-1b; Wed, 18 Nov 2026 16:57:30 +0100 From: Liu Kui Date: Wed, 18 Nov 2026 23:57:02 +0800 MIME-Version: 1.0 Message-Id: <20261118-b4-vstor-155302-sgl-folio-v2-1-bc5e45a53792@virtuozzo.com> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/32OzQ6CMBCEX4Xs2SXd8iN48j0MBygF1iA1LTQK4 d0F9OxxMjPfzAJOW9YOLsECVnt2bIZNyFMAqiuHViPXmwYpZEpEZ6xi9G40FilJIiHRtT02pme DqcqjjPIqF7KErf+0uuHXwb5BpxizkKD4Gm6q7lqNO3mPdrwj38cLT0fhN5j9GfSEhJGoY5GnU stIXD3bcTLzbEJlHlCs6/oBTh/MzuEAAAA= X-Change-ID: 20261117-b4-vstor-155302-sgl-folio-6c93819b902a To: Konstantin Khorenko X-Mailer: b4 0.16.0 X-OZ-Fwd: true Cc: azaitsev@virtuozzo.com, devel@openvz.org, Liu Kui Subject: [Devel] [PATCH hci-8.1 v2] fs/fuse kio: build the rdma sgl from folios X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org pcs_sgl_buf_init_from_msg() assumes there is only one 4k page per bio_vec segment, it counts the number of bio_vec segments and uses it for allocating the 4k page array and the scatterlist. However since commit ed62e3c51fa2 ("fs/fuse kio: teach pcs_umem about hugepage-backed mappings") a bio_vec segment over a hugepage-backed buffer can cover more than one 4k page, so the page array and the scatterlist allocated based on the number of segments are too small to hold all 4k pages, resulting in sg_next() returning NULL and sg_set_page() oopsing: BUG: kernel NULL pointer dereference, address: 0000000000000000 RIP: pcs_sgl_buf_init_from_msg+0x1ee/0x300 [fuse_kio_pcs] pcs_rdma_rw_init_from_msg rio_submit_rdma_read rio_handle_rx_immediate rio_handle_rx pcs_rdma_xmit rpc_queue_work Fix it by switching to folios, so a scatterlist entry can still hold an entire message segment regardless of whether it is hugepage backed. The scatterlist now holds the folio references, so the page array and its cleanup callback can be removed. Size the scatterlist by the segment count, with extra entries when a segment exceeds the device DMA segment limit. An inline array of two entries covers a hugepage-backed buffer without an allocation. Keep track of the DMA mapped entry count returned by ib_dma_map_sg() separately, so that the unmap and the folio puts are done correctly. A kvec over vmalloc memory is not physically contiguous and iov_iter_extract_pages() only returns its first page, so reject kvec iterators and let the MR fallback handle them. The only one that gets here is the fiemap reply buffer. https://virtuozzo.atlassian.net/browse/VSTOR-155302 Fixes: ed62e3c51fa2 ("fs/fuse kio: teach pcs_umem about hugepage-backed mappings") Feature: vStorage Signed-off-by: Liu Kui --- Fix for the NULL deref in pcs_sgl_buf_init_from_msg() on a kernel-direct client with hugepage-backed MR pools. https://virtuozzo.atlassian.net/browse/VSTOR-155302 --- Changes in v2: - reject kvec iterators and leave them to the MR fallback, a kvec over vmalloc memory is not physically contiguous (fiemap reply buffer) - name the commit that introduced the hugepage-backed bio_vec segments, add the Fixes and Feature tags - drop the page-size clause from the max_seg check, the count is then an upper bound however the length is split over the segments - Link to v1: http://lore.virtuozzo.com/20261118-b4-vstor-155302-sgl-folio-v1-1-30d40962e230@virtuozzo.com --- fs/fuse/kio/pcs/pcs_rdma_rw.c | 209 +++++++++++++++++++++++------------------- fs/fuse/kio/pcs/pcs_rdma_rw.h | 12 +-- 2 files changed, 119 insertions(+), 102 deletions(-) diff --git a/fs/fuse/kio/pcs/pcs_rdma_rw.c b/fs/fuse/kio/pcs/pcs_rdma_rw.c index eaf456002584..dc85bf7ff379 100644 --- a/fs/fuse/kio/pcs/pcs_rdma_rw.c +++ b/fs/fuse/kio/pcs/pcs_rdma_rw.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "pcs_rdma_rw.h" @@ -33,160 +34,175 @@ static unsigned int dma_dir_to_it_dir(enum dma_data_direction dir) return DMA_TO_DEVICE ? WRITE : READ; } +/* Drop the reference each of the first cnt entries holds on its folio. */ +static void sgl_put_folios(struct scatterlist *sgl, size_t cnt) +{ + struct scatterlist *sg; + int i; + + for_each_sg(sgl, sg, cnt, i) + folio_put(page_folio(sg_page(sg))); +} + +/* Build a scatterlist over the message range [offset, end_offset), one entry per folio. */ int pcs_sgl_buf_init_from_msg(struct pcs_sgl_buf *sbuf, unsigned int dir, struct pcs_msg *msg, - size_t offset, size_t end_offset, gfp_t gfp, bool allow_gaps) + size_t offset, size_t end_offset, gfp_t gfp, bool allow_gaps, + unsigned int max_seg) { struct iov_iter it; - size_t msg_offset; + size_t msg_offset, foff, len, off; + struct page *page, **pp = &page; struct scatterlist *sg; - int ret, i; + struct folio *folio; + ssize_t got; + int ret, cnt; if (offset >= end_offset || end_offset > msg->size) return -EINVAL; - sbuf->pg_cnt = 0; + /* count the entries, one per segment unless a segment is longer than max_seg */ sbuf->sg_cnt = 0; - sbuf->page_clean = put_page; - - iov_iter_kvec(&it, dir, NULL, 0, 0); msg_offset = offset; while (msg_offset < end_offset) { - size_t len; + msg->get_iter(msg, msg_offset, &it, dir); - if (!iov_iter_count(&it)) - 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_single_seg_count(&it); + len = iov_iter_count(&it); if (len > end_offset - msg_offset) len = end_offset - msg_offset; - iov_iter_advance(&it, len); + /* may overcount here, which is rare and harmless */ + sbuf->sg_cnt += it.nr_segs; msg_offset += len; - sbuf->sg_cnt++; - } - sbuf->pages = RE_NULL(kzalloc(sizeof(struct page*) * sbuf->sg_cnt, - gfp)); - if (!sbuf->pages) - return -ENOMEM; + /* This can only happen to a hugepage over umem. Though the default dma max + * segment size is 64kB if the driver doesn't configure it, most modern IB + * drivers use a much larger segment size, so this is a very rare case. + * The sum is an upper bound however the length is split over the segments, + * we may overcount, which again is harmless. + */ + if (unlikely(len > max_seg)) + sbuf->sg_cnt += DIV_ROUND_UP(len, max_seg); + } - sbuf->sgl = RE_NULL(kzalloc(sizeof(struct scatterlist) * sbuf->sg_cnt, - gfp)); - if (!sbuf->sgl) { - ret = -ENOMEM; - goto fail_pg; + if (sbuf->sg_cnt <= ARRAY_SIZE(sbuf->inline_sgl)) { + sbuf->sgl = sbuf->inline_sgl; + } else { + sbuf->sgl = RE_NULL(kzalloc(sizeof(struct scatterlist) * sbuf->sg_cnt, gfp)); + if (!sbuf->sgl) + return -ENOMEM; } sg_init_table(sbuf->sgl, sbuf->sg_cnt); + /* fill the entries, one folio reference each, and count the 4k pages */ iov_iter_kvec(&it, dir, NULL, 0, 0); + sbuf->pg_cnt = 0; msg_offset = offset; sg = sbuf->sgl; + cnt = 0; while (msg_offset < end_offset) { - size_t off, len; + if (WARN_ON_ONCE(!sg)) { + ret = -EINVAL; + goto fail; + } if (!iov_iter_count(&it)) msg->get_iter(msg, msg_offset, &it, dir); - len = iov_iter_get_pages2(&it, sbuf->pages + sbuf->pg_cnt, - PAGE_SIZE, 1, &off); - if (len <= 0) { - ret = -EINVAL; - goto fail_sgl; - } - + /* 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); + if (got != 1) { + ret = got < 0 ? got : -EINVAL; + goto fail; + } + + folio = page_folio(page); + foff = folio_page_idx(folio, page) * PAGE_SIZE + off; + len = min_t(size_t, len, max_seg); + iov_iter_advance(&it, len - 1); if (!allow_gaps && - ((msg_offset != offset && !IS_ALIGNED(off, PAGE_SIZE)) || - ((msg_offset + len != end_offset) && !IS_ALIGNED(off + len, PAGE_SIZE)))) { - iov_iter_revert(&it, len); + ((msg_offset != offset && !IS_ALIGNED(foff, PAGE_SIZE)) || + ((msg_offset + len != end_offset) && !IS_ALIGNED(foff + len, PAGE_SIZE)))) { ret = -EINVAL; - goto fail_sgl; + goto fail; } - sg = sg_next(sg); + folio_get(folio); + sg_set_folio(sg, folio, len, foff); + sbuf->pg_cnt += DIV_ROUND_UP((foff & (PAGE_SIZE - 1)) + len, PAGE_SIZE); + cnt++; msg_offset += len; + sg = sg_next(sg); } + /* the count is an upper bound, close the list at the last used entry */ + sg_mark_end(&sbuf->sgl[cnt - 1]); + sbuf->sg_cnt = cnt; + return 0; -fail_sgl: - kfree(sbuf->sgl); -fail_pg: - for (i = 0; i < sbuf->pg_cnt; i++) - sbuf->page_clean(sbuf->pages[i]); - kfree(sbuf->pages); +fail: + sgl_put_folios(sbuf->sgl, cnt); + if (sbuf->sgl != sbuf->inline_sgl) + kfree(sbuf->sgl); return ret; } -static void pcs_sgl_buf_free_page(struct page *page) -{ - __free_page(page); -} - +/* Build a scatterlist of size bytes over freshly allocated 4k folios, one per entry. */ int pcs_sgl_buf_init(struct pcs_sgl_buf *sbuf, size_t size, gfp_t gfp) { struct scatterlist *sg; - int ret, i; + int i; if (size == 0) return -EINVAL; - sbuf->pg_cnt = 0; sbuf->sg_cnt = PAGE_ALIGN(size) >> PAGE_SHIFT; - sbuf->page_clean = pcs_sgl_buf_free_page; + sbuf->pg_cnt = sbuf->sg_cnt; - sbuf->pages = RE_NULL(kzalloc(sizeof(struct page*) * sbuf->sg_cnt, - gfp)); - if (!sbuf->pages) - return -ENOMEM; - - sbuf->sgl = RE_NULL(kzalloc(sizeof(struct scatterlist) * sbuf->sg_cnt, - gfp)); - if (!sbuf->sgl) { - ret = -ENOMEM; - goto fail_pg; + if (sbuf->sg_cnt <= ARRAY_SIZE(sbuf->inline_sgl)) { + sbuf->sgl = sbuf->inline_sgl; + } else { + sbuf->sgl = RE_NULL(kzalloc(sizeof(struct scatterlist) * sbuf->sg_cnt, gfp)); + if (!sbuf->sgl) + return -ENOMEM; } sg_init_table(sbuf->sgl, sbuf->sg_cnt); for_each_sg(sbuf->sgl, sg, sbuf->sg_cnt, i) { size_t sg_len = min_t(size_t, size, PAGE_SIZE); - sbuf->pages[sbuf->pg_cnt] = RE_NULL(alloc_page(gfp)); - if (!sbuf->pages[sbuf->pg_cnt]) { - ret = -ENOMEM; - goto fail_sgl; + struct folio *folio = RE_NULL(folio_alloc(gfp, 0)); + + if (!folio) { + sgl_put_folios(sbuf->sgl, i); + if (sbuf->sgl != sbuf->inline_sgl) + kfree(sbuf->sgl); + return -ENOMEM; } BUG_ON(!sg_len); - sg_set_page(sg, sbuf->pages[sbuf->pg_cnt], sg_len, 0); + sg_set_folio(sg, folio, sg_len, 0); size -= sg_len; - sbuf->pg_cnt++; } return 0; - -fail_sgl: - kfree(sbuf->sgl); -fail_pg: - for (i = 0; i < sbuf->pg_cnt; i++) - sbuf->page_clean(sbuf->pages[i]); - kfree(sbuf->pages); - - return ret; } +/* Drop the folio references and free the list. */ void pcs_sgl_buf_destroy(struct pcs_sgl_buf *sbuf) { - int i; - - kfree(sbuf->sgl); - - for (i = 0; i < sbuf->pg_cnt; i++) - sbuf->page_clean(sbuf->pages[i]); - kfree(sbuf->pages); + sgl_put_folios(sbuf->sgl, sbuf->sg_cnt); + if (sbuf->sgl != sbuf->inline_sgl) + kfree(sbuf->sgl); } int pcs_ib_mr_pool_init(struct pcs_ib_mr_pool *pool, struct ib_pd *pd, @@ -291,7 +307,7 @@ int pcs_rdma_rw_init_from_msg(struct pcs_rdma_rw *rw, struct ib_device *dev, rw->dir = dir; ret = pcs_sgl_buf_init_from_msg(&rw->sbuf, dma_dir_to_it_dir(dir), msg, offset, end_offset, - gfp, true); + gfp, true, ib_dma_max_seg_size(dev)); if (ret) return ret; @@ -301,11 +317,11 @@ int pcs_rdma_rw_init_from_msg(struct pcs_rdma_rw *rw, struct ib_device *dev, ret = ret < 0 ? ret : -EIO; goto fail_sgl; } - rw->sbuf.sg_cnt = ret; + rw->sbuf.dma_cnt = ret; - rw->nr_wrs = DIV_ROUND_UP(rw->sbuf.sg_cnt, sge_per_wr); + rw->nr_wrs = DIV_ROUND_UP(rw->sbuf.dma_cnt, sge_per_wr); - rw->sges = RE_NULL(kzalloc(sizeof(struct ib_sge) * rw->sbuf.sg_cnt, gfp)); + rw->sges = RE_NULL(kzalloc(sizeof(struct ib_sge) * rw->sbuf.dma_cnt, gfp)); if (!rw->sges) { ret = -ENOMEM; goto fail_dma; @@ -319,7 +335,7 @@ int pcs_rdma_rw_init_from_msg(struct pcs_rdma_rw *rw, struct ib_device *dev, sg = rw->sbuf.sgl; sge = rw->sges; - sge_cnt = rw->sbuf.sg_cnt; + sge_cnt = rw->sbuf.dma_cnt; for (i = 0; i < rw->nr_wrs; i++) { struct ib_rdma_wr *wr = rw->wrs + i; int num_sge = min_t(size_t, sge_cnt, sge_per_wr); @@ -388,14 +404,15 @@ static int pcs_rdma_mr_init_common(struct pcs_rdma_mr *mr, struct ib_device *dev mr->pd = pd; mr->dir = dir; mr->size = size; + /* the MR page list is sized in 4k pages, an entry may span many */ mr->ib_mr_pool = ib_mr_pool && ib_mr_pool->mr_type == IB_MR_TYPE_MEM_REG && - ib_mr_pool->max_num_sg >= mr->sbuf.sg_cnt ? ib_mr_pool : NULL; + ib_mr_pool->max_num_sg >= mr->sbuf.pg_cnt ? ib_mr_pool : NULL; ret = RE_INV(ib_dma_map_sg(dev, mr->sbuf.sgl, mr->sbuf.sg_cnt, dir)); if (ret <= 0) return ret < 0 ? ret : -EIO; - mr->sbuf.sg_cnt = ret; + mr->sbuf.dma_cnt = ret; if (mr->ib_mr_pool) { mr->mr = RE_NULL(pcs_ib_mr_pool_get(mr->ib_mr_pool)); @@ -405,16 +422,16 @@ static int pcs_rdma_mr_init_common(struct pcs_rdma_mr *mr, struct ib_device *dev } } else { /* fallback */ mr->mr = RE_PTR_INV(ib_alloc_mr(pd, IB_MR_TYPE_MEM_REG, - mr->sbuf.sg_cnt)); + mr->sbuf.pg_cnt)); if (IS_ERR(mr->mr)) { ret = PTR_ERR(mr->mr); goto fail_dma; } } - ret = RE_INV(ib_map_mr_sg(mr->mr, mr->sbuf.sgl, mr->sbuf.sg_cnt, + ret = RE_INV(ib_map_mr_sg(mr->mr, mr->sbuf.sgl, mr->sbuf.dma_cnt, NULL, PAGE_SIZE)); - if (ret != mr->sbuf.sg_cnt) { + if (ret != mr->sbuf.dma_cnt) { ret = ret < 0 ? ret : -EIO; goto fail_mr; } @@ -457,7 +474,7 @@ int pcs_rdma_mr_init_from_msg(struct pcs_rdma_mr *mr, struct ib_device *dev, int ret; ret = pcs_sgl_buf_init_from_msg(&mr->sbuf, dma_dir_to_it_dir(dir), msg, offset, end_offset, - gfp, false); + gfp, false, ib_dma_max_seg_size(dev)); if (ret) return ret; @@ -527,7 +544,7 @@ void pcs_rdma_mr_sync_for_cpu(struct pcs_rdma_mr *mr, size_t size) struct scatterlist *sg; unsigned int i; - for_each_sg(mr->sbuf.sgl, sg, mr->sbuf.sg_cnt, i) { + for_each_sg(mr->sbuf.sgl, sg, mr->sbuf.dma_cnt, i) { size_t sg_len = min_t(size_t, size, sg_dma_len(sg)); ib_dma_sync_single_for_cpu(mr->dev, sg_dma_address(sg), @@ -544,7 +561,7 @@ void pcs_rdma_mr_sync_for_device(struct pcs_rdma_mr *mr, size_t size) struct scatterlist *sg; unsigned int i; - for_each_sg(mr->sbuf.sgl, sg, mr->sbuf.sg_cnt, i) { + for_each_sg(mr->sbuf.sgl, sg, mr->sbuf.dma_cnt, i) { size_t sg_len = min_t(size_t, size, sg_dma_len(sg)); ib_dma_sync_single_for_device(mr->dev, sg_dma_address(sg), diff --git a/fs/fuse/kio/pcs/pcs_rdma_rw.h b/fs/fuse/kio/pcs/pcs_rdma_rw.h index c8529ed16f13..6b53e93a67ee 100644 --- a/fs/fuse/kio/pcs/pcs_rdma_rw.h +++ b/fs/fuse/kio/pcs/pcs_rdma_rw.h @@ -47,16 +47,16 @@ extern u32 rdmaio_io_failing; struct pcs_sgl_buf { - struct page **pages; - size_t pg_cnt; - void (*page_clean)(struct page *page); - - struct scatterlist *sgl; + struct scatterlist *sgl; /* each entry holds a reference on its folio */ size_t sg_cnt; + size_t dma_cnt; /* entries after dma mapping, may be fewer than sg_cnt */ + size_t pg_cnt; /* 4k pages covered, sizes the MR page list */ + struct scatterlist inline_sgl[2]; /* enough for a hugepage-backed range */ }; int pcs_sgl_buf_init_from_msg(struct pcs_sgl_buf *sbuf, unsigned int dir, struct pcs_msg *msg, - size_t offset, size_t end_offset, gfp_t gfp, bool allow_gaps); + size_t offset, size_t end_offset, gfp_t gfp, bool allow_gaps, + unsigned int max_seg); int pcs_sgl_buf_init(struct pcs_sgl_buf *sbuf, size_t size, gfp_t gfp); void pcs_sgl_buf_destroy(struct pcs_sgl_buf *sbuf); --- base-commit: d816dd0e4cdc45208ba0c488d295c5b2f943e079 change-id: 20261117-b4-vstor-155302-sgl-folio-6c93819b902a Best regards, -- Liu Kui _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel