linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: Kinglong Mee <kinglongmee@gmail.com>
Cc: Linux NFS Mailing List <linux-nfs@vger.kernel.org>
Subject: Re: [PATCH 1/2] NFSD: Treat rq_reserved when initializing xdr_buf
Date: Mon, 11 Aug 2014 15:15:50 -0400	[thread overview]
Message-ID: <20140811191550.GF9095@fieldses.org> (raw)
In-Reply-To: <53E2EE27.5010603@gmail.com>

On Thu, Aug 07, 2014 at 11:10:31AM +0800, Kinglong Mee wrote:
> After calling svc_reserve() with a small length,
> nfsd does't treat it in svcxdr_init_encode().
> 
> So, when testing conflock, got message as,
> 
> [  970.127216] RPC request reserved 88 but used 116

rq_reserved should always be set no smaller than the maximum possible
size of the reply, given everything we know about the request.

So the bug is that rq_reserved was set to small.

The risk of returning a reply larger than rq_reserved is a relatively
rare deadlock, so I'd rather just stick to the log warning than convert
it to a hard error.

The solution in this case is to fix the incorrect estimate.

--b.

> 
> Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
> ---
>  fs/nfsd/nfs4proc.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
> index 5e0dc52..084e46e 100644
> --- a/fs/nfsd/nfs4proc.c
> +++ b/fs/nfsd/nfs4proc.c
> @@ -1245,17 +1245,20 @@ static void svcxdr_init_encode(struct svc_rqst *rqstp,
>  	struct xdr_stream *xdr = &resp->xdr;
>  	struct xdr_buf *buf = &rqstp->rq_res;
>  	struct kvec *head = buf->head;
> +	int tlen = 0;
>  
>  	xdr->buf = buf;
>  	xdr->iov = head;
>  	xdr->p   = head->iov_base + head->iov_len;
> -	xdr->end = head->iov_base + PAGE_SIZE - rqstp->rq_auth_slack;
> +	tlen = PAGE_SIZE - rqstp->rq_auth_slack;
> +	xdr->end = head->iov_base + min(tlen, rqstp->rq_reserved);
>  	/* Tail and page_len should be zero at this point: */
>  	buf->len = buf->head[0].iov_len;
>  	xdr->scratch.iov_len = 0;
>  	xdr->page_ptr = buf->pages - 1;
> -	buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages)
> +	tlen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages)
>  		- rqstp->rq_auth_slack;
> +	buf->buflen = min(tlen, rqstp->rq_reserved);
>  }
>  
>  /*
> -- 
> 1.9.3
> 

      reply	other threads:[~2014-08-11 19:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-07  3:10 [PATCH 1/2] NFSD: Treat rq_reserved when initializing xdr_buf Kinglong Mee
2014-08-11 19:15 ` J. Bruce Fields [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140811191550.GF9095@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=kinglongmee@gmail.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).