Received: by 2002:a05:6358:615c:b0:12b:e873:ff31 with SMTP id 28csp3674928rwt; Fri, 4 Aug 2023 08:07:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEKoIYePYbr4EyMd75k1rvrQRFvnvOEk8JuMBRQdoKSO5a552HclTNBoITaCrAGmFdo5xlL X-Received: by 2002:a17:907:7608:b0:99b:f405:e737 with SMTP id jx8-20020a170907760800b0099bf405e737mr1708495ejc.71.1691161645926; Fri, 04 Aug 2023 08:07:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691161645; cv=none; d=google.com; s=arc-20160816; b=qMKBe9p6bcN0ZBNNqJxyICNMiAE9iuWa03I9XPXZ/z6h2ePJArquQAvRbdlzcypYkd VhoEzYbt5mSoUy2FWO3LOwvGJ5vx2OVpSITbu84XUNIyDYkJdy0tv0VViJj4ru+YFhQD H/ZCXr0RUG28Rrt4gLxZO0Cc2i2ORPYeDh1ZwjNyaY8KBfuVyHojbcmtYv0iNXh5t005 uyHvWOxJqn+wtDsAFUTVhprRVYmeRyuDzmpwjv7yeYgeSlxhPVhmMqi+DWhS8UBjndpa /iaAlNfbKLJYXdjGxJnRI1EJf3BkN1Ez04oqL0zpv5rFwcWKd73SiXnEhuyeaxnbv6EG k8Tg== 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=dHYA2IrNpONr95AjtpQxWSgfxf0e6O6AgQhvb/6sHd0=; fh=2+k2UmE8LvafU5qNzgAjM/Dn4M5GGukEmX+hFN4rQ+Y=; b=SOhsx4J/Ja5Tvy7q1EJjs2MtzZYBroecfj3BKOX3vOVhIYO5kD4aeJt7x9Av0gP6KF 9gse3EoIsEkDF+3eaoAzTkkF3Lrg69DqAju1FHe5Tn4E8T5dGwnSnquvbLRjdd0rrCo0 tIWH0XE46IfJbazTdmG6UrmEHXDSh6uKrEMlcaQHwJ+kz5mUBO8B6typIapPLiRjLXW2 MWG1ULuF97Ww9M3z8RhzTKleGLdNGMVixt/hi09KSkNyvXxpeOja2cN4iRrXwr84chfp 2v6C7efJ9+JT+hQegaWky6+eCWQrG/20YRM7ciC3Tz3UKCwN6H6Gmq1OPiayQfGydxZJ TDZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Mb3fsKF7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c24-20020a170906155800b009930253bc69si1702355ejd.1011.2023.08.04.08.06.25; Fri, 04 Aug 2023 08:07:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Mb3fsKF7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229831AbjHDNPF (ORCPT + 99 others); Fri, 4 Aug 2023 09:15:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229778AbjHDNPE (ORCPT ); Fri, 4 Aug 2023 09:15:04 -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 63BF249C6 for ; Fri, 4 Aug 2023 06:13:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691154817; 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=dHYA2IrNpONr95AjtpQxWSgfxf0e6O6AgQhvb/6sHd0=; b=Mb3fsKF7nWAP5tEweftJBcZOpkklNbANNwwz6NrrDuNab0KcqA6WLBxjXZnSSJQzDOzmFV 6qsn6yCqbW9tjdjJrLbkenMAoXFVaW5m+j6N1EbMlxOpory7P1Cf+55ZeQmey91i0nnE1y 3YaYgwYXP8vY4mSxdoFNHGKkmsetEeE= 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-317-SckMlT4pN9uRr4YSQHtsZw-1; Fri, 04 Aug 2023 09:13:34 -0400 X-MC-Unique: SckMlT4pN9uRr4YSQHtsZw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DC7F28022EF; Fri, 4 Aug 2023 13:13:33 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC457492CA6; Fri, 4 Aug 2023 13:13:32 +0000 (UTC) From: David Howells To: Ilya Dryomov , Xiubo Li Cc: David Howells , Jeff Layton , Dongsheng Yang , ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 01/18] iov_iter: Add function to see if buffer is all zeros Date: Fri, 4 Aug 2023 14:13:10 +0100 Message-ID: <20230804131327.2574082-2-dhowells@redhat.com> In-Reply-To: <20230804131327.2574082-1-dhowells@redhat.com> References: <20230804131327.2574082-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=-2.1 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, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 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 Add a function to scan a buffer and indicate if all of the bytes contained therein are zero. Signed-off-by: David Howells --- include/linux/uio.h | 1 + lib/iov_iter.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/linux/uio.h b/include/linux/uio.h index ff81e5ccaef2..49de7b8a8890 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -264,6 +264,7 @@ static inline bool iov_iter_is_copy_mc(const struct iov_iter *i) #endif size_t iov_iter_zero(size_t bytes, struct iov_iter *); +bool iov_iter_is_zero(const struct iov_iter *i, size_t count); bool iov_iter_is_aligned(const struct iov_iter *i, unsigned addr_mask, unsigned len_mask); unsigned long iov_iter_alignment(const struct iov_iter *i); diff --git a/lib/iov_iter.c b/lib/iov_iter.c index b667b1e2f688..ec9e3e1a11a9 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -566,6 +566,28 @@ size_t iov_iter_zero(size_t bytes, struct iov_iter *i) } EXPORT_SYMBOL(iov_iter_zero); +/** + * iov_iter_is_zero - Return true if the buffer is entirely zeroed + * @i: The iterator describing the buffer + * @count: Amount of buffer to scan + * + * Scans the specified amount of the supplied buffer and returns true if only + * zero bytes are found therein and false otherwise. + */ +bool iov_iter_is_zero(const struct iov_iter *i, size_t count) +{ + struct iov_iter j = *i, *pj = &j; + void *p; + + iterate_and_advance(pj, count, base, len, count, + ({ p = memchr_inv(base, 0, len); p ? p - base : len; }), + ({ p = memchr_inv(base, 0, len); p ? p - base : len; }) + ) + + return !count; +} +EXPORT_SYMBOL(iov_iter_is_zero); + size_t copy_page_from_iter_atomic(struct page *page, unsigned offset, size_t bytes, struct iov_iter *i) {