Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp3057967rdb; Fri, 22 Sep 2023 17:32:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEx0BmaLGgJn3Z0We1m5qU0tGtkanVE3f2H03UTMrt2Kjb1C0mDq+Cnv2DCy5D9+4ZH5hve X-Received: by 2002:a05:6a21:3d87:b0:159:1bd8:fc7a with SMTP id bj7-20020a056a213d8700b001591bd8fc7amr1040490pzc.40.1695429123772; Fri, 22 Sep 2023 17:32:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695429123; cv=none; d=google.com; s=arc-20160816; b=n0X6XzoQPiP+glu5OF/Hur3JHi/d/p+ZXz/82vhKsVzjt4m3Mhu7r1l4PmMpx/xdFC 42fqsQ7+PBDafwEBPL2dcw/QubEoiFiFVPoXVL7FbgREG1FWG6LzT27EK7XhSJgdRzfj xY7X/t+NvNDa0s+jO2E171d2xgKLf3DbuWFnK7djaDTeKrKm0Wm7kl9vWvu7EuBUnuoG LYuROu4aD3ngfs7iIOm2AeeP9hPE/IENDbm2+P9SV8TYUlyhJoEenUgtEAwB0fvY7fri Q6Z3pDdIPCZx6yTfh2R/Fc75OzESLmyTPqA6y0ijrnCML92yyvrcUaosr2rELArEEckL sdbQ== 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=hYOoT+N3+ZXg5kUOP5JOmaiFuOq7EbJgQKHzR3cvg3M=; fh=dzqEI/am1IoNVOMZmTOChre3TckBGjOgtLT35fkBuy0=; b=jRMwvJEOw1Dqk640HOu7HYAin3Cg0AcrNDY+EKp49usCTDl/ftGa7K+jGy1Q4M4NId CWpOuU5DoCnWxZ+Jd4Dce+nPnTzNDFlTWKzr3L3NlFDlPq6vyJgKYclDom0Ck7tiZS58 tGGHiamLrqmDzAOrJwGaNpjFABzK7nJP2KGd138az9st56DtWsYfZ4W4dMup546uuL9O DwbQgnB7sgs6rn/V44zhc6+8vW3mfOHRDorfbJGIECjnO0lNqBjW+J4rjGX5nRYAYcuC gRaxYVInZ6o++khBPaidPBHfRhRNQIcmikfpyZWSbCw7Cn/FRvBgA+kYdbFSekCFgpVh wg/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QlbdtTKS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id x4-20020a17090a6c0400b00274b944508fsi7114126pjj.39.2023.09.22.17.32.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 17:32:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QlbdtTKS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id DD4958092D8D; Fri, 22 Sep 2023 05:16:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233648AbjIVMQ2 (ORCPT + 99 others); Fri, 22 Sep 2023 08:16:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234071AbjIVMEZ (ORCPT ); Fri, 22 Sep 2023 08:04:25 -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 8F2861B5 for ; Fri, 22 Sep 2023 05:02:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695384178; 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=hYOoT+N3+ZXg5kUOP5JOmaiFuOq7EbJgQKHzR3cvg3M=; b=QlbdtTKSRMEP5wQpKgMDMNzKzcp/YMPv0ZgWrcBak6v5FpWoyslKZJtgGfLyTZtfqtc6hf 6ziYPLpqpKcCLlhSCJkorB6U4/S8s5LCPfvojAXf9A2njseq99J/PUn4Vyo/8j4CjJ70He r5IL13zYjOGFGhVDy1qns+Qa/bUKmVo= 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-619-ZTcYAYuYMcqv6NQGNev8hg-1; Fri, 22 Sep 2023 08:02:55 -0400 X-MC-Unique: ZTcYAYuYMcqv6NQGNev8hg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 9DF423816C89; Fri, 22 Sep 2023 12:02:54 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id EFD0D711282; Fri, 22 Sep 2023 12:02:52 +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 v6 09/13] iov_iter: Add a kernel-type iterator-only iteration function Date: Fri, 22 Sep 2023 13:02:23 +0100 Message-ID: <20230922120227.1173720-10-dhowells@redhat.com> In-Reply-To: <20230922120227.1173720-1-dhowells@redhat.com> References: <20230922120227.1173720-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Fri, 22 Sep 2023 05:16:27 -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 --- Notes: Changes ======= ver #6) - Document the priv2 arg of iterate_and_advance_kernel(). include/linux/iov_iter.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/include/linux/iov_iter.h b/include/linux/iov_iter.h index 270454a6703d..d8733dc22b54 100644 --- a/include/linux/iov_iter.h +++ b/include/linux/iov_iter.h @@ -271,4 +271,36 @@ 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. + * @priv2: More 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 */