From patchwork Wed Sep 20 22:22:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13393501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84A1FC2FC0C for ; Wed, 20 Sep 2023 22:23:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D65C6B01AA; Wed, 20 Sep 2023 18:23:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 17BE46B01AB; Wed, 20 Sep 2023 18:23:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0E746B01AE; Wed, 20 Sep 2023 18:23:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id DACFF6B01AA for ; Wed, 20 Sep 2023 18:23:05 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B6005807DB for ; Wed, 20 Sep 2023 22:23:05 +0000 (UTC) X-FDA: 81258402330.15.7094402 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 00597140017 for ; Wed, 20 Sep 2023 22:23:03 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VByCaamG; spf=pass (imf26.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695248584; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QdaDFgQ/IdiUz+wPFCKvBKKks+ni1Kcs8Sp2gYxHcOI=; b=gICFspeO6mns9RaTZzY+VNi0unsGRYb0hcA+R0YHjStCPJI5uHShKuHCtFZVMlSywwD4MD oEz3iMmflS74bSrWe2wb7bPfe42SvqbF8iEYKom6PCRXiMfamuvPHF3gkewf81A4nPB3Pr seWu5MllaOi74ZWrxwHvZ8+lg9UKGDM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695248584; a=rsa-sha256; cv=none; b=EKoP/kjK0RpezuPHNdaZxoGpNsb9FxsRaGduSfDCTZ5f3PzOQwMV3FJTGLRGjZpa5WoNTk MI+eEwUqZYpy4qe4LBMJ9k3zHsj264dmmPGpHhBIbMZ9nDffh5Vwt2StfvV5Z5PbL8oD7+ VgcqAnh0WP9bCeGMH/znwNb9y1aCDZ8= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VByCaamG; spf=pass (imf26.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695248583; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QdaDFgQ/IdiUz+wPFCKvBKKks+ni1Kcs8Sp2gYxHcOI=; b=VByCaamGkRzP7TVTaBOe18GreNttnd8igZQyaSadjsRKS8Vu0MryCL5tJddrRYeVO7M06h 17BxnWOhgSCGhI+03IgWmbc4k1GlAxE2Z3coFTtiAFBgSOd/JjfxYQJv3GhWmLdwjpdYFs jKuhyldQLAYnalypcvuY3M6QA36UWeE= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-169-pcHmzeEEOaC540eqzQ0x5A-1; Wed, 20 Sep 2023 18:22:56 -0400 X-MC-Unique: pcHmzeEEOaC540eqzQ0x5A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EEE4328EC113; Wed, 20 Sep 2023 22:22:55 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55F5F2156A27; Wed, 20 Sep 2023 22:22:54 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , Christoph Hellwig , Christian Brauner , David Laight , Matthew Wilcox , Jeff Layton , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 07/11] iov_iter: Add a kernel-type iterator-only iteration function Date: Wed, 20 Sep 2023 23:22:27 +0100 Message-ID: <20230920222231.686275-8-dhowells@redhat.com> In-Reply-To: <20230920222231.686275-1-dhowells@redhat.com> References: <20230920222231.686275-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Stat-Signature: hckym45hcm8fn1h74nasrhhogsbboaw9 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 00597140017 X-Rspam-User: X-HE-Tag: 1695248583-509285 X-HE-Meta: U2FsdGVkX1+eLc8wPA9gu3/QRIn/srwXlburi4Gt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3oFQKSXtfCYZzR6nN7dx+ge4CJWInGdsmTHjh18AE9N9MkicoKcmYldYL3u+ANQy/qyz0DVDb45gl+ZZWj6LYnijGC7esLSSQZ4cOhZVb0m1VDdRE3PH4OcLc7fXjHLu40ricn47OUVN3+m7gfm+UmvwoBmxrQm3Nx7QO19QIYrnSdnnDocvz/xdEZ44PfFplTQG4uaAB/Ss9vjVBs/qvNbHngWsXHpiXqF0NpLkeIl04WbwMdMKbuYx9gYFj9j3ve98tbBaWMoXByhFXmaeb93WFeVY546vRRCOLpww15FPX9Hjn9CctjunffnHc7bgUuo975grFWhI6wmHhMhH/1FTFFGRAhugpp5AtgSnjn9MFgBRc1LIpO8o4j2nsDuY8+Rqbm66veh8Ibg9HEeaCqCIbg30CtYryR4lmSKeOMjyY/g8vRKIfXz7im+sM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add an iteration function that can only iterate over kernel internal-type iterators (ie. BVEC, KVEC, XARRAY) and not user-backed iterators (ie. UBUF and IOVEC). This allows for smaller iterators to be built when it is known the caller won't have a user-backed iterator. Signed-off-by: David Howells cc: Alexander Viro cc: Jens Axboe cc: Christoph Hellwig cc: Christian Brauner cc: Matthew Wilcox cc: Linus Torvalds cc: David Laight cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- include/linux/iov_iter.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/include/linux/iov_iter.h b/include/linux/iov_iter.h index 270454a6703d..a94d605d7386 100644 --- a/include/linux/iov_iter.h +++ b/include/linux/iov_iter.h @@ -271,4 +271,35 @@ size_t iterate_and_advance(struct iov_iter *iter, size_t len, void *priv, return iterate_and_advance2(iter, len, priv, NULL, ustep, step); } +/** + * iterate_and_advance_kernel - Iterate over a kernel iterator + * @iter: The iterator to iterate over. + * @len: The amount to iterate over. + * @priv: Data for the step functions. + * @step: Processing function; given kernel addresses. + * + * Like iterate_and_advance2(), but rejected UBUF and IOVEC iterators and does + * not take a user-step function. + */ +static __always_inline +size_t iterate_and_advance_kernel(struct iov_iter *iter, size_t len, void *priv, + void *priv2, iov_step_f step) +{ + if (unlikely(iter->count < len)) + len = iter->count; + if (unlikely(!len)) + return 0; + + if (iov_iter_is_bvec(iter)) + return iterate_bvec(iter, len, priv, priv2, step); + if (iov_iter_is_kvec(iter)) + return iterate_kvec(iter, len, priv, priv2, step); + if (iov_iter_is_xarray(iter)) + return iterate_xarray(iter, len, priv, priv2, step); + if (iov_iter_is_discard(iter)) + return iterate_discard(iter, len, priv, priv2, step); + WARN_ON_ONCE(1); + return 0; +} + #endif /* _LINUX_IOV_ITER_H */