Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1698037rdb; Wed, 20 Sep 2023 17:42:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHdfflHZq1Hqjbyviv/KpIsEnEnBRK/P9Rak8kdN/wQwfV3bR6aJf5Pvl0Fw9SN8LtEMtWR X-Received: by 2002:a17:903:22cc:b0:1c5:b4a1:ff6 with SMTP id y12-20020a17090322cc00b001c5b4a10ff6mr4680888plg.45.1695256972650; Wed, 20 Sep 2023 17:42:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695256972; cv=none; d=google.com; s=arc-20160816; b=V1U4CZdoWYEw4hGpHuBeWbIOoo+1yOu1ZxvGxwq4MdW5uJCk/VS0dP7ds313AvoDZH wAVeU1Y/rMqfxs7CdV43V5tCQEF9DBpGo9Y3NRqwhrlEEyqyK8rfKKyY/a6k7FANwvPE SOxB2s3foiu03ITP/eMZGQ5IC4XX5YSHy4EJWmRi7VMDE1lfJR2DllBT2Kw7m45AGj69 qB4DvOZC5xTSmQ+86iDO5OR/P0Dcx1c69PAxOuSlewpT7zFMFbTeFBlPAT6KlUyDZQw4 uKA1bO1T2ruw2lVyBxdJtqvEc9BGn8Lcek7rzNHNTi5C0guL88Bo9aOQtW9RAthTtQNf MAUw== 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:cc:to:from :dkim-signature; bh=QdaDFgQ/IdiUz+wPFCKvBKKks+ni1Kcs8Sp2gYxHcOI=; fh=dzqEI/am1IoNVOMZmTOChre3TckBGjOgtLT35fkBuy0=; b=SBBhc0z/P1Rfxj0TuDB8Wgj/TjjQJOnnVqAfMfaJC1S642AiXbMeOU2voFLDBbLdTb RxTEaR9H/sy4EX65j3z+EejrZpVdvv1GWFEepZ7PaAAWZ1yjvHLx5PA003yIclQ8nOcB WdyZcAGtgI/IRNyN4tiDdz+AHwTUdBXxg2HR8TWCCyHZcZU2Hlek+E+ZY4uw0rX3vF21 3UTC/oiFh+eydeXZ+VJNh8zw31B4j37sKwqug7hWUQpAZXEL++cWum/QPfoPZiH66h5D 8LZKEJkAqIpTWZwy1WL9uVIwcW6oif6Ymp1qGGuEl/TmLy7bDgtbCQZrqC5QYKt8LzDf K01g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VByCaamG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id h7-20020a170902f54700b001c3e9b0bae1si270980plf.443.2023.09.20.17.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 17:42:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VByCaamG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 001208072827; Wed, 20 Sep 2023 15:25:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229794AbjITWYk (ORCPT + 99 others); Wed, 20 Sep 2023 18:24:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229650AbjITWYY (ORCPT ); Wed, 20 Sep 2023 18:24:24 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD5E812B for ; Wed, 20 Sep 2023 15:23:03 -0700 (PDT) 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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 20 Sep 2023 15:25:43 -0700 (PDT) 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 */