Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp993446pxb; Wed, 3 Mar 2021 23:51:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJwMB200EA+/V1FBzfMO3Wt6s6UOxRt4AtfyICq1kLvNWXRqFge0i+D+0In/8PjvQ9Q4HSB/ X-Received: by 2002:a17:906:a51:: with SMTP id x17mr2890556ejf.25.1614844294217; Wed, 03 Mar 2021 23:51:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614844294; cv=none; d=google.com; s=arc-20160816; b=C1SG4ncWaaffcKhkAURjH1sppkh3tyATYE6rDsfxLtbSco2PmPNgBMzcnQR5+3wZhe /EV5lOQx4ddlB6V1N4iVNUAS7CvpvLLoxACXYOk8+1bLuQ3jW+QE5xG8+sv7vmOfYwJ7 K4YY4y8p6WTlrIEv4JGMMrdikYpEVN9bfpEE2EcI6jwylk8GSWdpOSjVyRXE6tuAViQV hy/LY1lTVeTOsvsrbIwg4/DsmsObPg0iqIYL7kpkYEuh+sW/jA9Fuo/C6pCs4fKrYIPZ D/WXJND4jsgDuNs29TDCbA/jGcMBANMFOFTt2eVH+DlsC2naQpErTu01ZjPeaDMW8ZPw /+Tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:from:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:date :dkim-signature:dkim-filter; bh=hBcskT1LkvlWxCE2U9pifU2ayZeLoxkveE6/dSa0o3c=; b=gpYp/+zx/ux6DDwxiPh8XQSyWUMbxtARwGwlEwobOqKRhJ09nGAoMtZswPTmfOxcJ4 31WmM0q9DZUn8OyZwquW8z4vHvBRceJYAPWEyymUAakdkGKxyXRSrOfTcy3yd41cIZ1f Tbuh+FaAKXte8aRzGYvOfvvDKK2TXBT0Au4gL+k9SqNO8DfiVGFZK5TUPtobM4scvGDu xWqAb7jBaghHgS2CAxbI8Z/xSHpBQTNbFhEl7Ol4QCqw5zGAvH0gzchXmG9xdDuVGmAB 4yviPHDWAJRaWnyvmEvghvkk7xV2KQLdZpBQ0GvPEHtOOqNvk9r+DLv2Ek5yGRYquWmf d/vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fieldses.org header.s=default header.b=o7ANXYBa; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u25si6686289edo.148.2021.03.03.23.51.11; Wed, 03 Mar 2021 23:51:34 -0800 (PST) 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=@fieldses.org header.s=default header.b=o7ANXYBa; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343816AbhCCK5h (ORCPT + 99 others); Wed, 3 Mar 2021 05:57:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1835983AbhCBWMq (ORCPT ); Tue, 2 Mar 2021 17:12:46 -0500 Received: from fieldses.org (fieldses.org [IPv6:2600:3c00:e000:2f7::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62BE7C06178A for ; Tue, 2 Mar 2021 14:11:31 -0800 (PST) Received: by fieldses.org (Postfix, from userid 2815) id 54D661C81; Tue, 2 Mar 2021 17:11:30 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.11.0 fieldses.org 54D661C81 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fieldses.org; s=default; t=1614723090; bh=hBcskT1LkvlWxCE2U9pifU2ayZeLoxkveE6/dSa0o3c=; h=Date:To:Cc:Subject:References:In-Reply-To:From:From; b=o7ANXYBa+AJ/v3kZxc/hA3ZTW4bdjzuQNpWFvZI0tLvhBXt+NIwONnHs/QKiMyN4b rTsbP247OBDf8Zf05P0yfD+dsgRAdN4s7TY0lvVWKDs73of8ERvpQf7eFQ0JyvA/q3 KniZvVowDHiHEWTab2UBZoXjdBnJN6sR5xmAemLs= Date: Tue, 2 Mar 2021 17:11:30 -0500 To: Chuck Lever Cc: linux-nfs@vger.kernel.org Subject: Re: [PATCH v1 19/42] SUNRPC: Fix xdr_get_next_encode_buffer() page boundary handling Message-ID: <20210302221130.GG3400@fieldses.org> References: <161461145466.8508.13379815439337754427.stgit@klimt.1015granger.net> <161461183307.8508.17196295994390119297.stgit@klimt.1015granger.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <161461183307.8508.17196295994390119297.stgit@klimt.1015granger.net> User-Agent: Mutt/1.5.21 (2010-09-15) From: bfields@fieldses.org (J. Bruce Fields) Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On Mon, Mar 01, 2021 at 10:17:13AM -0500, Chuck Lever wrote: > The description of commit 2825a7f90753 ("nfsd4: allow encoding > across page boundaries") states: > > > Also we can't handle a new operation starting close to the end of > > a page. > > But does not detail why this is the case. That wasn't every helpful of me, sorry. > Subtracting the scratch buffer's "shift" value from the remaining > stream space seems to make reserving space close to the end of the > buf->pages array reliable. So, why is that? Thinking this through: When somebody asks for a buffer that would straddle a page boundary, with frag1bytes at the end of this page and frag2bytes at the start of the next page, we instead give them a buffer starting at start of the next page. That gives them a nice contiguous buffer to write into. When they're done using it, we fix things up by copying what they wrote back to where it should be. That means we're temporarily wasting frag1bytes of space. So, I don't know, maybe that's the logic behind subtracing frag1bytes from space_left. It means you may end up with xdr->end frag1bytes short of the next page. I'm not sure that's right. --b. > > This change is needed to make entry encoding with struct xdr_stream, > introduced in a subsequent patch, work correctly when it approaches > the end of the dirlist buffer. > > Fixes: 2825a7f90753 ("nfsd4: allow encoding across page boundaries") > Signed-off-by: Chuck Lever > --- > net/sunrpc/xdr.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c > index 3964ff74ee51..043b67229792 100644 > --- a/net/sunrpc/xdr.c > +++ b/net/sunrpc/xdr.c > @@ -978,7 +978,7 @@ static __be32 *xdr_get_next_encode_buffer(struct xdr_stream *xdr, > * shifted this one back: > */ > xdr->p = (void *)p + frag2bytes; > - space_left = xdr->buf->buflen - xdr->buf->len; > + space_left = xdr->buf->buflen - xdr->buf->len - frag1bytes; > xdr->end = (void *)p + min_t(int, space_left, PAGE_SIZE); > xdr->buf->page_len += frag2bytes; > xdr->buf->len += nbytes; >