Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp1060058iof; Mon, 6 Jun 2022 19:30:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSAF3My7V6JqVa9I/eAnWEcMesTYXMAHFswQiwHlexQSXDaPKdklqorIOOZ/ciLx8Dl99s X-Received: by 2002:a17:906:7944:b0:6da:b834:2f3e with SMTP id l4-20020a170906794400b006dab8342f3emr25092069ejo.353.1654569026269; Mon, 06 Jun 2022 19:30:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654569026; cv=none; d=google.com; s=arc-20160816; b=nvF6EU3RxK/Ntd2BH2Z7GEDZNGH/6rYwrckSHIq5aT7+tK9CpnF3mIv6XFocibxmFY Z7C4q96JT5ZBfRHFd40Lez6dIFQ69I30kjOuxYTPaJwW5CX2ReStYAT/dapM4ypleGr3 5RNpjKJmyngIN1QA7foxhsZHuAGuQj7kh00NYYaXGqKDYOQBOw1mjMy/YSMXVoBj+Wdg X9uHVsCdIOrBc4+xXO5/CfjS6NJFeqiEqrPRYnFmSJJHTAvz+nzoC+SM1Eso4xryUbL9 gJkFvD8IezWRW97Hh4IS/GlNZqyvB3xxW+FBYFZ2q4vPSGHbQUwoSykGmAffKLQ8p+wX FlTw== 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=ktiBAQ/wgvwptzNAOn9nPvZvQrzjysCqUMdBc8mNzTw=; b=Mox0+DH6gZqAXWSW5XLTYANF1gTqwlnfxwEhHJQF5oIXmokLrt2uxtYFhEnqius7ED nHZFNVEYm1ku5kzg5qSVfysAZhttQ1lq3V8XMK6VcZUOReGh/iCvJt8pNrtbOFfOHucJ SwAmsNuf4fpTiqWLrs1mJbzsV+YkAnpqQ0KfaSklCWcVcOsURu7sLhR72VZ52uegM+Rd Pr2gywu7g1DVcKXrD0xzg7PpDks9x8bApZF8NKiVj+XTyqC3vh1qEJIBuZH/jXUNPCK7 6vFj+dePEmS5v5WoolJTba+8rk2xd70s6EcSedyR6r5jdx7ZxK+c0Go/bX+WAOanjobo AEFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fieldses.org header.s=default header.b=WPUOboAf; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fieldses.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he13-20020a1709073d8d00b007072e51c723si2000799ejc.365.2022.06.06.19.29.46; Mon, 06 Jun 2022 19:30:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@fieldses.org header.s=default header.b=WPUOboAf; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fieldses.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231557AbiFFWJm (ORCPT + 99 others); Mon, 6 Jun 2022 18:09:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231521AbiFFWJl (ORCPT ); Mon, 6 Jun 2022 18:09:41 -0400 Received: from fieldses.org (fieldses.org [IPv6:2600:3c00:e000:2f7::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93DADBE1A for ; Mon, 6 Jun 2022 15:09:40 -0700 (PDT) Received: by fieldses.org (Postfix, from userid 2815) id 08AF86C90; Mon, 6 Jun 2022 18:09:39 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.11.0 fieldses.org 08AF86C90 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fieldses.org; s=default; t=1654553379; bh=ktiBAQ/wgvwptzNAOn9nPvZvQrzjysCqUMdBc8mNzTw=; h=Date:To:Cc:Subject:References:In-Reply-To:From:From; b=WPUOboAf6TuslUvsZHx8Fe20biVnFhZPoQr9fjcmru+oPU5/A3Ke3T1UGsfIj/UpR KI9vYL3/hFiwY8GE3CMgAP6LSyjy8q9LqbJamTXBQffffcAy0Z3MpHrV5uCwjqLm20 EmZ16rPjUjHD9bWB68CxZlmSIm9TcPMyNvZljiL4= Date: Mon, 6 Jun 2022 18:09:38 -0400 To: Chuck Lever Cc: linux-nfs@vger.kernel.org Subject: Re: [PATCH v1 1/5] SUNRPC: Fix the calculation of xdr->end in xdr_get_next_encode_buffer() Message-ID: <20220606220938.GE15057@fieldses.org> References: <165445865736.1664.4497130284832282034.stgit@bazille.1015granger.net> <165445910560.1664.5852151724543272982.stgit@bazille.1015granger.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <165445910560.1664.5852151724543272982.stgit@bazille.1015granger.net> User-Agent: Mutt/1.5.21 (2010-09-15) From: bfields@fieldses.org (J. Bruce Fields) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On Sun, Jun 05, 2022 at 03:58:25PM -0400, Chuck Lever wrote: > I found that NFSD's new NFSv3 READDIRPLUS XDR encoder was screwing up > right at the end of the page array. xdr_get_next_encode_buffer() does > not compute the value of xdr->end correctly: > > * The check to see if we're on the final available page in xdr->buf > needs to account for the space consumed by @nbytes. > > * The new xdr->end value needs to account for the portion of @nbytes > that is to be encoded into the previous buffer. > > Fixes: 2825a7f90753 ("nfsd4: allow encoding across page boundaries") > Signed-off-by: Chuck Lever > --- > net/sunrpc/xdr.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c > index df194cc07035..b57cf9df4de8 100644 > --- a/net/sunrpc/xdr.c > +++ b/net/sunrpc/xdr.c > @@ -979,7 +979,11 @@ static __be32 *xdr_get_next_encode_buffer(struct xdr_stream *xdr, > */ > xdr->p = (void *)p + frag2bytes; > space_left = xdr->buf->buflen - xdr->buf->len; > - xdr->end = (void *)p + min_t(int, space_left, PAGE_SIZE); > + if (space_left - nbytes >= PAGE_SIZE) > + xdr->end = (void *)p + PAGE_SIZE; > + else > + xdr->end = (void *)p + space_left - frag1bytes; > + I think that's right. Couldn't you just make that - xdr->end = (void *)p + min_t(int, space_left, PAGE_SIZE); + xdr->end = (void *)p + min_t(int, space_left - nbytes, PAGE_SIZE); ? (Note we know space_left >= nbytes from the second "if" of this function.) No strong opinion either way, really, I just wonder if I'm missing something. --b. > xdr->buf->page_len += frag2bytes; > xdr->buf->len += nbytes; > return p; >