Skip to content

Commit 35f71f3

Browse files
chucklevergregkh
authored andcommitted
xprtrdma: Fix XDRBUF_SPARSE_PAGES support
commit 15261b9 upstream. Olga K. observed that rpcrdma_marsh_req() allocates sparse pages only when it has determined that a Reply chunk is necessary. There are plenty of cases where no Reply chunk is needed, but the XDRBUF_SPARSE_PAGES flag is set. The result would be a crash in rpcrdma_inline_fixup() when it tries to copy parts of the received Reply into a missing page. To avoid crashing, handle sparse page allocation up front. Until XATTR support was added, this issue did not appear often because the only SPARSE_PAGES consumer always expected a reply large enough to always require a Reply chunk. Reported-by: Olga Kornievskaia <kolga@netapp.com> Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Cc: <stable@vger.kernel.org> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6a9a98f commit 35f71f3

1 file changed

Lines changed: 31 additions & 9 deletions

File tree

‎net/sunrpc/xprtrdma/rpc_rdma.c‎

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,31 @@ rpcrdma_nonpayload_inline(const struct rpcrdma_xprt *r_xprt,
179179
r_xprt->rx_ep->re_max_inline_recv;
180180
}
181181

182+
/* ACL likes to be lazy in allocating pages. For TCP, these
183+
* pages can be allocated during receive processing. Not true
184+
* for RDMA, which must always provision receive buffers
185+
* up front.
186+
*/
187+
static noinline int
188+
rpcrdma_alloc_sparse_pages(struct xdr_buf *buf)
189+
{
190+
struct page **ppages;
191+
int len;
192+
193+
len = buf->page_len;
194+
ppages = buf->pages + (buf->page_base >> PAGE_SHIFT);
195+
while (len > 0) {
196+
if (!*ppages)
197+
*ppages = alloc_page(GFP_NOWAIT | __GFP_NOWARN);
198+
if (!*ppages)
199+
return -ENOBUFS;
200+
ppages++;
201+
len -= PAGE_SIZE;
202+
}
203+
204+
return 0;
205+
}
206+
182207
/* Split @vec on page boundaries into SGEs. FMR registers pages, not
183208
* a byte range. Other modes coalesce these SGEs into a single MR
184209
* when they can.
@@ -233,15 +258,6 @@ rpcrdma_convert_iovs(struct rpcrdma_xprt *r_xprt, struct xdr_buf *xdrbuf,
233258
ppages = xdrbuf->pages + (xdrbuf->page_base >> PAGE_SHIFT);
234259
page_base = offset_in_page(xdrbuf->page_base);
235260
while (len) {
236-
/* ACL likes to be lazy in allocating pages - ACLs
237-
* are small by default but can get huge.
238-
*/
239-
if (unlikely(xdrbuf->flags & XDRBUF_SPARSE_PAGES)) {
240-
if (!*ppages)
241-
*ppages = alloc_page(GFP_NOWAIT | __GFP_NOWARN);
242-
if (!*ppages)
243-
return -ENOBUFS;
244-
}
245261
seg->mr_page = *ppages;
246262
seg->mr_offset = (char *)page_base;
247263
seg->mr_len = min_t(u32, PAGE_SIZE - page_base, len);
@@ -867,6 +883,12 @@ rpcrdma_marshal_req(struct rpcrdma_xprt *r_xprt, struct rpc_rqst *rqst)
867883
__be32 *p;
868884
int ret;
869885

886+
if (unlikely(rqst->rq_rcv_buf.flags & XDRBUF_SPARSE_PAGES)) {
887+
ret = rpcrdma_alloc_sparse_pages(&rqst->rq_rcv_buf);
888+
if (ret)
889+
return ret;
890+
}
891+
870892
rpcrdma_set_xdrlen(&req->rl_hdrbuf, 0);
871893
xdr_init_encode(xdr, &req->rl_hdrbuf, rdmab_data(req->rl_rdmabuf),
872894
rqst);

0 commit comments

Comments
 (0)