Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2304611pxa; Mon, 3 Aug 2020 12:38:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxi+4gEY62BkCm7QOXik3Xh6+o1osg4l14Pbs3q0DoHr3B7pXXXGYHb3uV2z6neYH3po2Yn X-Received: by 2002:a50:8ace:: with SMTP id k14mr17910900edk.0.1596483534431; Mon, 03 Aug 2020 12:38:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596483534; cv=none; d=google.com; s=arc-20160816; b=qbFQ3pgTa16jubfRbxWjojoJbX4pjnZ/JyiZHi9kLnQsfWqhQ29gW5WRKY4M1UhCx4 d1v/DpkMVXTlURw8Qzz7LqAeS52VovPq9yQmlFVsUbUrVnW84FztNKFRjiSBcDgi0smA L65gLA6jiuxZzEPEWprxeh+qL4G+oGzzboj551+bBiclkL9MIxJMJR71EtCAQ/w3YTWR ztulPbs68+vbycf8bNrWLsS8fFjLl/iwXopTn+oRSEkwYu+3eZkKzvHwlsf6PGbBEQQD X2Gp1DmCWRR2AFcHnbs4IzDclavImgNksFOteRyxm5y9bj1C4YbTMlWo9XZWtdg9iP6J dm+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=RjdWzxA18k+zTNZZxtPPihNSkZrVBU5Rfc5b6kxvL4c=; b=GoL060fCmjS58LjIYjbIrJMLng9L5J7rKAfLaQ/qwjGtyGMoN9PJDtjNVl92ewLjgO qg9LjXpjspwRjRqx5VDGTVkJy7JBi5IKLmbwE7PU85EGZSYTI7KcyIEY61nFimy0RcAA WYAbJvGwQc2IZhmFHY3CWuJzdtPbNPbZljd4Yu3BeDJqgIGBm3Sqh26noaP/Q6OhtBx4 KzI3SZlqUD25bTWeNGDGCy1EuzCl0ykFvGLOl8b16kPM6/twJWl+lFavVm0P2AnwzJAc Pw7jnU8KFL4ecTEtoDbTrwb8TcYTzKWaKK15v+hV3FULWswxDQxdp/4Blkz/3I9Lp2GT 73nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vN8aa0m+; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n29si4072097eda.587.2020.08.03.12.38.26; Mon, 03 Aug 2020 12:38:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vN8aa0m+; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728127AbgHCTiQ (ORCPT + 99 others); Mon, 3 Aug 2020 15:38:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727813AbgHCTiP (ORCPT ); Mon, 3 Aug 2020 15:38:15 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39688C06174A for ; Mon, 3 Aug 2020 12:38:15 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id a21so39863738ejj.10 for ; Mon, 03 Aug 2020 12:38:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RjdWzxA18k+zTNZZxtPPihNSkZrVBU5Rfc5b6kxvL4c=; b=vN8aa0m+uqDl1vM8HM1Jgbf7z9JJ52rOmcGikgfTAToEuVTRVK9YjCTnX5kovTmp27 RhkP9SkFJCr0rpCkX6ynAatuOuXCK9EGtcBjYBE9ROs1Wqhj4LnrCW0dp5h/6lD7ZC/d dIVRNdBn/J1n25NT/qLhX/poBmENlK91UqL4xWOsLECV7Cw2Mru8NsaDs4c49JkQlBez +4+EoGBEkv0/I0d0toae7D0UrRXmfqTa4oT9RYVTMrn7mB6RAj7SkXMp/KmBqBRqmtTr B7XIwA7jSo1skVotaaafSpS8Ix0leBisREFn4XwnkUQR3YVyo3+11U2BqfV46CC70+yu o0Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RjdWzxA18k+zTNZZxtPPihNSkZrVBU5Rfc5b6kxvL4c=; b=Q1ipe4bSCKz8qFeTWdfJI189t9sVkvuYUgF26nubnrnf+RMtC32fp4iMNNz/zGmQI6 50OsJrUkFpGjvh5KR/rztvrV16L/638Abzt2OIh6/zAgv5R6UlO/ySI9AFgvYunMj2aF 5s61H6Bh6ZvWWeQSEaEbhF9TCbKGOHIzFLlwfkpjYZa/begPyleQ8P8jWGQNBsedvMR+ XvGgPIHIXaifqs0PokegyjqKGQQjNFzZ7sOLF1NJH0s0paQdIo6fWSCV8CowAKSPdbfn 7xhshHEmx+EGV06+IfCHgigmRw/+YXqIaBfEaYx9vsMNSdTdXpfLvavC3FKY/dhNunIL YfVg== X-Gm-Message-State: AOAM5334w3FdslBohBsW1pRVm4RgYxfoTJxr2IoMf2KJj+IDGK4RPVs7 gKTy1M71k23VWi1RyRHeeY70cGr/VfbKNjWr4Ik= X-Received: by 2002:a17:906:d042:: with SMTP id bo2mr17518001ejb.152.1596483493846; Mon, 03 Aug 2020 12:38:13 -0700 (PDT) MIME-Version: 1.0 References: <20200803165954.1348263-1-Anna.Schumaker@Netapp.com> <20200803165954.1348263-2-Anna.Schumaker@Netapp.com> In-Reply-To: From: Anna Schumaker Date: Mon, 3 Aug 2020 15:37:57 -0400 Message-ID: Subject: Re: [PATCH v3 1/6] SUNRPC: Implement xdr_reserve_space_vec() To: Chuck Lever Cc: Bruce Fields , Linux NFS Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Hi Chuck, On Mon, Aug 3, 2020 at 3:21 PM Chuck Lever wrote: > > Hi Anna- > > > On Aug 3, 2020, at 12:59 PM, schumaker.anna@gmail.com wrote: > > > > From: Anna Schumaker > > > > Reserving space for a large READ payload requires special handling when > > reserving space in the xdr buffer pages. One problem we can have is use > > of the scratch buffer, which is used to get a pointer to a contiguous > > region of data up to PAGE_SIZE. When using the scratch buffer, calls to > > xdr_commit_encode() shift the data to it's proper alignment in the xdr > > buffer. If we've reserved several pages in a vector, then this could > > potentially invalidate earlier pointers and result in incorrect READ > > data being sent to the client. > > > > I get around this by looking at the amount of space left in the current > > page, and never reserve more than that for each entry in the read > > vector. This lets us place data directly where it needs to go in the > > buffer pages. > > Nit: This appears to be a refactoring change that should be squashed > together with 2/6. My default was to leave sunrpc and nfs changes as separate patches, but I can squash them together if you want me to! Anna > > > > Signed-off-by: Anna Schumaker > > --- > > include/linux/sunrpc/xdr.h | 2 ++ > > net/sunrpc/xdr.c | 45 ++++++++++++++++++++++++++++++++++++++ > > 2 files changed, 47 insertions(+) > > > > diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h > > index 22c207b2425f..bac459584dd0 100644 > > --- a/include/linux/sunrpc/xdr.h > > +++ b/include/linux/sunrpc/xdr.h > > @@ -234,6 +234,8 @@ typedef int (*kxdrdproc_t)(struct rpc_rqst *rqstp, struct xdr_stream *xdr, > > extern void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf, > > __be32 *p, struct rpc_rqst *rqst); > > extern __be32 *xdr_reserve_space(struct xdr_stream *xdr, size_t nbytes); > > +extern int xdr_reserve_space_vec(struct xdr_stream *xdr, struct kvec *vec, > > + size_t nbytes); > > extern void xdr_commit_encode(struct xdr_stream *xdr); > > extern void xdr_truncate_encode(struct xdr_stream *xdr, size_t len); > > extern int xdr_restrict_buflen(struct xdr_stream *xdr, int newbuflen); > > diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c > > index be11d672b5b9..6dfe5dc8b35f 100644 > > --- a/net/sunrpc/xdr.c > > +++ b/net/sunrpc/xdr.c > > @@ -648,6 +648,51 @@ __be32 * xdr_reserve_space(struct xdr_stream *xdr, size_t nbytes) > > } > > EXPORT_SYMBOL_GPL(xdr_reserve_space); > > > > + > > +/** > > + * xdr_reserve_space_vec - Reserves a large amount of buffer space for sending > > + * @xdr: pointer to xdr_stream > > + * @vec: pointer to a kvec array > > + * @nbytes: number of bytes to reserve > > + * > > + * Reserves enough buffer space to encode 'nbytes' of data and stores the > > + * pointers in 'vec'. The size argument passed to xdr_reserve_space() is > > + * determined based on the number of bytes remaining in the current page to > > + * avoid invalidating iov_base pointers when xdr_commit_encode() is called. > > + */ > > +int xdr_reserve_space_vec(struct xdr_stream *xdr, struct kvec *vec, size_t nbytes) > > +{ > > + int thislen; > > + int v = 0; > > + __be32 *p; > > + > > + /* > > + * svcrdma requires every READ payload to start somewhere > > + * in xdr->pages. > > + */ > > + if (xdr->iov == xdr->buf->head) { > > + xdr->iov = NULL; > > + xdr->end = xdr->p; > > + } > > + > > + while (nbytes) { > > + thislen = xdr->buf->page_len % PAGE_SIZE; > > + thislen = min_t(size_t, nbytes, PAGE_SIZE - thislen); > > + > > + p = xdr_reserve_space(xdr, thislen); > > + if (!p) > > + return -EIO; > > + > > + vec[v].iov_base = p; > > + vec[v].iov_len = thislen; > > + v++; > > + nbytes -= thislen; > > + } > > + > > + return v; > > +} > > +EXPORT_SYMBOL_GPL(xdr_reserve_space_vec); > > + > > /** > > * xdr_truncate_encode - truncate an encode buffer > > * @xdr: pointer to xdr_stream > > -- > > 2.27.0 > > > > -- > Chuck Lever > > >