From patchwork Wed Sep 13 16:56:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13383569 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 BFBC9EE01E9 for ; Wed, 13 Sep 2023 16:57:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D1D246B01F8; Wed, 13 Sep 2023 12:57:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CCE3C6B01F9; Wed, 13 Sep 2023 12:57:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B48426B01FA; Wed, 13 Sep 2023 12:57:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9B9846B01F8 for ; Wed, 13 Sep 2023 12:57:12 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7611BB39B0 for ; Wed, 13 Sep 2023 16:57:12 +0000 (UTC) X-FDA: 81232179504.28.110FACB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf23.hostedemail.com (Postfix) with ESMTP id B80C0140017 for ; Wed, 13 Sep 2023 16:57:10 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IyPDjQjg; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694624230; 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=rhHz2rkHFFU/pzH+hQA/LimHSXRi7J1g2T3941mk2Gc=; b=deS0yULua5WwnfFEUKgZBLZ0IECUZUxiYqLH9HMVkDZILNtCxXb2cinV2rkIpAVyNZE0hk o3DLzIIg0GB7lddbjXki4FJQURfBZUEXFB828fY5nIX5vDtmdOCPSo3xxtM2OkrbaBQxUm K+hPfW4fmqMkW4LPIvBLWCjPohBSU8E= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IyPDjQjg; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694624230; a=rsa-sha256; cv=none; b=VtiXVz908A47wV3oC43+UliLaVbFohf9AXeNYkeHjvtiC0+zHoiQAYDIEvCRx9NC+T+KWI i8/+Op3sHy363e0dQthlZYyA9R0Suf7t6n7PWOJdRmGbzha0cBnsfI8eoFqDace/dpHRJH sLf6lI8Hs4nmkUQLqfTpsIBiv5y3Xks= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694624230; 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=IyPDjQjgaw2ztZeGQCRT9mlirGb+KBEKluH4X6WRwQwQYCRClFHFqquMpVKqIsnv3ykIDw 28byJwR8j5j6Awf3bclKbdl2kmqQFD9EjKughsmvQtg6rnU8vKB3ne3wUOjcLplZ1BRnpT Ey/Cihw9KAwxNmvJIAkMQMlcD2vnO3E= 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 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: B80C0140017 X-Stat-Signature: u9ytsc6f8bbpaem9gs8dsjemikhpec58 X-HE-Tag: 1694624230-646471 X-HE-Meta: U2FsdGVkX1+poH7evL1hw24zG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/jWYVeLB5szgDK/wDoSnJ9CVal7Cx7p67jCkimjB20wgQx6y4gI4dTVRCAC+ZYw8UCYiQJ/+xr1Kt/ELCn6EaJKKI8/ofRGEds/JWEJF0Xfgx3svNWab7ere/NGL2BXRaf7s/h3vKAq/wPAW08FKpD36bovBLoP50DkhU0xuLcRnl+KR1qta1tJNUedv3XbQc/DnZ3oDU3/SHKVcSR4Jua8hRQA+PyoeitBZoTZJVHk/nRBsqNAWbBHomLR/tS6sXbOTi5VFk+xwPl7GWjgIqhWpDN9z9tKPC84M+ill6s7A1R6HvyhSooSe1tYn9p+fItBqi1l8d3ureoULwSDA5TI90zAzZaNxBXuM2qu7zOwJKFPcy1AHgh+wLLYAaRPxoSRmo9PE8cZ2lTIsU8XHyoM96dZ1/SdN7Gu1yydYOACoBUCWUPS0f4YNCSEo6SDQ459TAKQKSX00= 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 | 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 */