Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1650460pxu; Tue, 24 Nov 2020 05:54:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJyZLSpCFCkG0Oc75gMN2J1xBxSR8CylYfzB4r0nLpUdk1oyIPVpEJPILpNtEZOLPOMWAKh2 X-Received: by 2002:a05:6402:22ab:: with SMTP id cx11mr3845312edb.98.1606226041728; Tue, 24 Nov 2020 05:54:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606226041; cv=none; d=google.com; s=arc-20160816; b=LaLp774Ps14w0EV46zkhm5jjKC4OEjR5x8LBudFq8peqP/iIeS6qERsR604DwsPK3n mydqtDw3zrdaxs8Z9utBd/lOvgAMgeift+w3kJ+PiBlk6Yfc8ogO4Pf8tE3fWqqhg6Mm IHfhYWCY2SZTcEOOeiLLY5kyQl+gDn+2S7gm+6NCfsHdz7T91XDYnpaw7o19A1Qqdffg 3aU04lEhc4pG6DAVYsNTwTeKSBLBYk70OKfqI9QWnLQH0vqdDk8qqdTlHaC6FxvTifo3 UsIccXq2GEEblKg5LSQEgNnyKzmcUYWNb1ORc4WTXt5eP44b6lGjq09ph1ltBho/pLmL 913A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=qn33TfajxdTOxscGFoqw9JSF/XJGbw22wjdUe2zyqx0=; b=VoJwybLRSFzirD4dCAQlXhY2UaFJ+Nh0Apx1O+NDFlac+By1gTYn9OWWoIh0gOUSLY mrIOiTbrY3QrphfuKncBXO1CMudkbW9ogiiNP+zK89UKJ9YM8nAvCpROd25ckRUmWYDZ b8MbcZqqQQg4uukc+eSDmHAHW77ofeSA/H4iCwGVxT/rRPgvffpyTfjGkLPubyOI0xho HPSBhM8TheEGTjjApDpMtBlf/dSVb6lMFXiTB2s/hOnCKrUDq0hdL9bNXzGTwgU8tEMw YH+Ogs6JdK0Xyk7BIuVHSYhcKMSBZbnN3PqP2pEG2QfQ62//FsFB0qTM8d2KpU854Pnr nyPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TUGjkQq8; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d24si8670740eds.446.2020.11.24.05.53.24; Tue, 24 Nov 2020 05:54:01 -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=@kernel.org header.s=default header.b=TUGjkQq8; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388588AbgKXNu3 (ORCPT + 99 others); Tue, 24 Nov 2020 08:50:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:44674 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388573AbgKXNu3 (ORCPT ); Tue, 24 Nov 2020 08:50:29 -0500 Received: from leira.hammer.space (c-68-36-133-222.hsd1.mi.comcast.net [68.36.133.222]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9025B20872 for ; Tue, 24 Nov 2020 13:50:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606225828; bh=pVN1NYJXByzgbl+Gege54jjNGn2XTbEaz6hjagDwx50=; h=From:To:Subject:Date:In-Reply-To:References:From; b=TUGjkQq8Eoetyy2StYVO67MBveK36AOU/HXQXp0Cab2E0/TPbI/J4G0e+VjU8rFcJ cdvC8WhjGrxn6gKEke0NT4cK8sNRqgwa06DLxLgAvZAR8t0EUOfQFaw9dRxNV4WNpb vBEUApp48+krg01FIHl4oigR604ZbnjVyl/JSFTg= From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v2 3/9] SUNRPC: Clean up helpers xdr_set_iov() and xdr_set_page_base() Date: Tue, 24 Nov 2020 08:50:19 -0500 Message-Id: <20201124135025.1097571-4-trondmy@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201124135025.1097571-3-trondmy@kernel.org> References: <20201124135025.1097571-1-trondmy@kernel.org> <20201124135025.1097571-2-trondmy@kernel.org> <20201124135025.1097571-3-trondmy@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust Allow xdr_set_iov() to set a base so that we can use it to set the cursor to a specific position in the kvec buffer. If the new base overflows the kvec/pages buffer in either xdr_set_iov() or xdr_set_page_base(), then truncate it so that we point to the end of the buffer. Finally, change both function to return the number of bytes remaining to read in their buffers. Signed-off-by: Trond Myklebust --- net/sunrpc/xdr.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c index bc7a622016ee..394297ec1cb9 100644 --- a/net/sunrpc/xdr.c +++ b/net/sunrpc/xdr.c @@ -970,19 +970,22 @@ void xdr_write_pages(struct xdr_stream *xdr, struct page **pages, unsigned int b } EXPORT_SYMBOL_GPL(xdr_write_pages); -static void xdr_set_iov(struct xdr_stream *xdr, struct kvec *iov, - unsigned int len) +static unsigned int xdr_set_iov(struct xdr_stream *xdr, struct kvec *iov, + unsigned int base, unsigned int len) { if (len > iov->iov_len) len = iov->iov_len; - xdr->p = (__be32*)iov->iov_base; + if (unlikely(base > len)) + base = len; + xdr->p = (__be32*)(iov->iov_base + base); xdr->end = (__be32*)(iov->iov_base + len); xdr->iov = iov; xdr->page_ptr = NULL; + return len - base; } -static int xdr_set_page_base(struct xdr_stream *xdr, - unsigned int base, unsigned int len) +static unsigned int xdr_set_page_base(struct xdr_stream *xdr, + unsigned int base, unsigned int len) { unsigned int pgnr; unsigned int maxlen; @@ -991,9 +994,11 @@ static int xdr_set_page_base(struct xdr_stream *xdr, void *kaddr; maxlen = xdr->buf->page_len; - if (base >= maxlen) - return -EINVAL; - maxlen -= base; + if (base >= maxlen) { + base = maxlen; + maxlen = 0; + } else + maxlen -= base; if (len > maxlen) len = maxlen; @@ -1011,14 +1016,14 @@ static int xdr_set_page_base(struct xdr_stream *xdr, pgend = PAGE_SIZE; xdr->end = (__be32*)(kaddr + pgend); xdr->iov = NULL; - return 0; + return len; } static void xdr_set_page(struct xdr_stream *xdr, unsigned int base, unsigned int len) { - if (xdr_set_page_base(xdr, base, len) < 0) - xdr_set_iov(xdr, xdr->buf->tail, xdr->nwords << 2); + if (xdr_set_page_base(xdr, base, len) == 0) + xdr_set_iov(xdr, xdr->buf->tail, 0, xdr_stream_remaining(xdr)); } static void xdr_set_next_page(struct xdr_stream *xdr) @@ -1055,12 +1060,9 @@ void xdr_init_decode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p, xdr->scratch.iov_base = NULL; xdr->scratch.iov_len = 0; xdr->nwords = XDR_QUADLEN(buf->len); - if (buf->head[0].iov_len != 0) - xdr_set_iov(xdr, buf->head, buf->len); - else if (buf->page_len != 0) - xdr_set_page_base(xdr, 0, buf->len); - else - xdr_set_iov(xdr, buf->tail, buf->len); + if (xdr_set_iov(xdr, buf->head, 0, buf->len) == 0 && + xdr_set_page_base(xdr, 0, buf->len) == 0) + xdr_set_iov(xdr, buf->tail, 0, buf->len); if (p != NULL && p > xdr->p && xdr->end >= p) { xdr->nwords -= p - xdr->p; xdr->p = p; -- 2.28.0