Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3420588rdb; Wed, 13 Sep 2023 11:25:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFp5uorSmLS/u2zgyAZSn3hni5DmFvoWrsk0dkosLWclWD6LYFPKLjejMJwR6K1SF4rWyak X-Received: by 2002:a05:6a20:3d8d:b0:154:a579:b0ff with SMTP id s13-20020a056a203d8d00b00154a579b0ffmr3515475pzi.19.1694629550030; Wed, 13 Sep 2023 11:25:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694629550; cv=none; d=google.com; s=arc-20160816; b=pSM1F+rTA16HAHCNTNCgrKkAdYqS7fcI52x37SW7iK9Wj8EQwTQc98IxKgFNv8ivPH vIXnNBV0QR1eFJsXyIQMhm1xDWxeAmmrxgLHcmD51VGExIGPz9pzvb1D60Z6xmzh7w/N zrlDiCwGsSog+PBHThG2E6QemHPk3d80sy4X93ayUFOr4+uuJie5jrquPaHFAi2cTFXm WLIQWJMAHTNwnHIZwf/DTUN7XYYgZA0cySVCerqqphV660oPLLSTIKuVRtzr/zyiEYfa uZrVZ/K3IwaQg4zUJkkR2RYGqWT5YEQmX/PD24DJR6okn/mkk4dWXmFnwCd4FU/aKmSi i7Qg== 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=rhHz2rkHFFU/pzH+hQA/LimHSXRi7J1g2T3941mk2Gc=; fh=JMFAeSz7Gk3tUajr4TCvrb0uYdtniI0MVPhc5ULEcNg=; b=Fa/K2KfQ0PUuaJJ+6lu9dLaT0aEznvNNWuVCnvQ6u7TfcYCT/2G2pRHqkXclPMzs0C gmHkUVI/r/Jd+9OIoLMw6iyNWQByAZGgtWYoKw2b4e0vbnoxja4Od2avwmERefPuxYOg OfijHOqFEtE6vfRoRFYxxfwANaIalBaATWWKyUIC3ef6njl7Gt34/TLwgQlp1wM/Qz0d 5r7FeFnJLzJ5IzECkea9OnvKeDH+9zuPSYzp7M3zZTTzbtaeNC0O0YtsXJRfbhmcNgIB XO4214AiV+l8Jhzl92wNFqN/wirVbarRN6PgQiupL3CzVQuCp/9wGVZHU2HpE+llW8vU kFHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AjUM9IHV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id b5-20020a170902650500b001c0f0103e99si10522024plk.126.2023.09.13.11.25.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 11:25:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AjUM9IHV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 5AA21826FAE9; Wed, 13 Sep 2023 09:58:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231436AbjIMQ61 (ORCPT + 99 others); Wed, 13 Sep 2023 12:58:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230451AbjIMQ6H (ORCPT ); Wed, 13 Sep 2023 12:58:07 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 92DFC1BF6 for ; Wed, 13 Sep 2023 09:57:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694624235; 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=rhHz2rkHFFU/pzH+hQA/LimHSXRi7J1g2T3941mk2Gc=; b=AjUM9IHV8EyrerwDylNpW8nXDKqeNL7PHx7rAPvhZ6YXLvsa/PJCesiK68L5PcNrQelbF9 jgyvkkDpbPMZ8Jq7lZdsSJqlvDvmK+0UCQqxMFyD5DpAwthuyuB8Nal+SGF1lwpsVqKIyM KBnJ8VcCNYz4BqODqsrPlcA3H61M+64= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-670-2tcJ0K_0Mga54Zz4FQYBNQ-1; Wed, 13 Sep 2023 12:57:08 -0400 X-MC-Unique: 2tcJ0K_0Mga54Zz4FQYBNQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 D5F09101A529; Wed, 13 Sep 2023 16:57:07 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B4AF1054FC1; Wed, 13 Sep 2023 16:57:06 +0000 (UTC) From: David Howells To: Al Viro , Linus Torvalds Cc: David Howells , Jens Axboe , 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 v4 06/13] iov_iter: Add a kernel-type iterator-only iteration function Date: Wed, 13 Sep 2023 17:56:41 +0100 Message-ID: <20230913165648.2570623-7-dhowells@redhat.com> In-Reply-To: <20230913165648.2570623-1-dhowells@redhat.com> References: <20230913165648.2570623-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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 (groat.vger.email [0.0.0.0]); Wed, 13 Sep 2023 09:58:51 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/include/linux/iov_iter.h b/include/linux/iov_iter.h index 836854847cdf..46e628640934 100644 --- a/include/linux/iov_iter.h +++ b/include/linux/iov_iter.h @@ -258,4 +258,39 @@ 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) +{ + size_t progress; + + if (unlikely(iter->count < len)) + len = iter->count; + if (unlikely(!len)) + return 0; + + if (iov_iter_is_bvec(iter)) + progress = iterate_bvec(iter, len, priv, priv2, step); + else if (iov_iter_is_kvec(iter)) + progress = iterate_kvec(iter, len, priv, priv2, step); + else if (iov_iter_is_xarray(iter)) + progress = iterate_xarray(iter, len, priv, priv2, step); + else if (WARN_ON_ONCE(unlikely(iter_is_ubuf(iter) || iter_is_iovec(iter)))) + progress = 0; + else + progress = len; + iter->count -= progress; + return progress; +} + #endif /* _LINUX_IOV_ITER_H */