From patchwork Thu Sep 14 22:15:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13386114 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 D0B88EEAA78 for ; Thu, 14 Sep 2023 22:15:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C7286B02FB; Thu, 14 Sep 2023 18:15:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 56A776B02FC; Thu, 14 Sep 2023 18:15:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E5DF6B02FD; Thu, 14 Sep 2023 18:15:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 28C426B02FB for ; Thu, 14 Sep 2023 18:15:49 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0AC591606E8 for ; Thu, 14 Sep 2023 22:15:49 +0000 (UTC) X-FDA: 81236611218.24.32FA276 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 4F77C12000D for ; Thu, 14 Sep 2023 22:15:47 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cIxpWzCd; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf29.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1694729747; 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=0wrDnIJNvyLeCaZ76kAPm12sjpZAz+xrWcuHtRTLq38=; b=kzh51LKMLQKF9doO250kI0pU5CZCmNphqZC5FnrCbtFBPij8TPjUqgLVAAGg94vwQSKdat r+Wx6qxn4SW7/3pD87bTimh3yAoi5SU+HICUAqhrnX9GrgY3QAs8kO6ek4JHXVQRyUAvwb i5wwysEvlRmb+69du6WE6W89Nuq3tsc= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cIxpWzCd; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf29.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694729747; a=rsa-sha256; cv=none; b=8eOi934b2GZuCLPsFZ+RqkChGYaduFRAkhbUXqZzaPcxf0d/bgblRVzasYCpgZGF0gsXRp x+gDctiB5p+MpYVKGSY9vWJU5XzmDFEWLOSFuEFY0IG37QsFlV68IuC4EIE0aUEMnxj+ic HMlqbfLgNwpEGpd4R9g642sZ14nTQMI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694729746; 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=0wrDnIJNvyLeCaZ76kAPm12sjpZAz+xrWcuHtRTLq38=; b=cIxpWzCd3/L0NyJ3NChZocRnbYTy/mBzbqxyxf25D71LpyNMEqc3djgT/H7Z6/vsIelmui Zkm0zdBxSYFWaeGPO0GtpRBNILGM+l0Ej91W9NeFMSY1VinTG5ye0EiPmG3jcJIvgJfpn2 TMsUTkiuzq+SSLDgTstmddLShrNlPq0= 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-489-UiPT6vSiMGSaaoOG4V0fzA-1; Thu, 14 Sep 2023 18:15:43 -0400 X-MC-Unique: UiPT6vSiMGSaaoOG4V0fzA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 919D8857A9E; Thu, 14 Sep 2023 22:15:42 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A6DF40C2070; Thu, 14 Sep 2023 22:15:40 +0000 (UTC) From: David Howells To: Al Viro , Linus Torvalds Cc: David Howells , Jens Axboe , Christoph Hellwig , Christian Brauner , David Laight , Matthew Wilcox , Brendan Higgins , David Gow , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Christian Brauner , David Hildenbrand , John Hubbard Subject: [RFC PATCH 4/9] iov_iter: Consolidate bvec pattern checking Date: Thu, 14 Sep 2023 23:15:21 +0100 Message-ID: <20230914221526.3153402-5-dhowells@redhat.com> In-Reply-To: <20230914221526.3153402-1-dhowells@redhat.com> References: <20230914221526.3153402-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspamd-Queue-Id: 4F77C12000D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ygpzgcb11ycxo8s5pdwop4n9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hx79wi+om3NLtf9WNA92bAt3dNKzJQNYO9/nJ3yZvnPGrUon+DRBWCk1Q7/LsadzMFR2kDjktPgKYkh96bwDNuzxcuC6S/4YiIeg9DUA0WKc6R4sLGdlgzx0Y25Z0o8kXimCGlR+MGOKBNyZN5kDJMnyCLikitegFTOEj1qn5I7P3E3grRpRogTl1l4ePywY9C2sVa3g7HhgnHzsHrf8gMsLAttsTUW1ggtP9s4IhPuSNFvgqKbFQ2IccrUFlxobS4nsMgxz2/FhvntOTf9xLoRm/6kXtfa6yviZ3j5RfJVX1sLiTEjnmhLK9M3e7+vSJCJtgjk2eAx3z6GyAQw2ShM7xfIVhmTIk4N2SOevoblbzw/ng/uh4EWhHaUu8Ip1ZMQt8VG8fEpJ5VyqEVJPiIWf7gqzNmNkVco2KdNEvKTBFF1Z3IXe/OfKeRPMY24Da0psUq2RIQn0bl 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: Make the BVEC-testing functions use the consolidated pattern checking functions to reduce the amount of duplicated code. Signed-off-by: David Howells cc: Christoph Hellwig cc: Christian Brauner cc: Jens Axboe cc: Al Viro cc: David Hildenbrand cc: John Hubbard cc: Brendan Higgins cc: David Gow cc: linux-kselftest@vger.kernel.org cc: kunit-dev@googlegroups.com cc: linux-mm@kvack.org cc: linux-fsdevel@vger.kernel.org --- lib/kunit_iov_iter.c | 42 +++++++++++------------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/lib/kunit_iov_iter.c b/lib/kunit_iov_iter.c index 4925ca37cde6..eb86371b67d0 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -107,9 +107,11 @@ static void iov_kunit_build_to_reference_pattern(struct kunit *test, u8 *scratch int i, patt = 0; memset(scratch, 0, bufsize); - for (; pr->page >= 0; pr++) + for (; pr->page >= 0; pr++) { + u8 *p = scratch + pr->page * PAGE_SIZE; for (i = pr->from; i < pr->to; i++) - scratch[i] = pattern(patt++); + p[i] = pattern(patt++); + } } /* @@ -124,8 +126,10 @@ static void iov_kunit_build_from_reference_pattern(struct kunit *test, u8 *buffe memset(buffer, 0, bufsize); for (; pr->page >= 0; pr++) { + size_t patt = pr->page * PAGE_SIZE; + for (j = pr->from; j < pr->to; j++) { - buffer[i++] = pattern(j); + buffer[i++] = pattern(patt + j); if (i >= bufsize) return; } @@ -287,13 +291,12 @@ static void __init iov_kunit_load_bvec(struct kunit *test, */ static void __init iov_kunit_copy_to_bvec(struct kunit *test) { - const struct iov_kunit_range *pr; struct iov_iter iter; struct bio_vec bvec[8]; struct page **spages, **bpages; u8 *scratch, *buffer; size_t bufsize, npages, size, copied; - int i, patt; + int i; bufsize = 0x100000; npages = bufsize / PAGE_SIZE; @@ -315,16 +318,7 @@ static void __init iov_kunit_copy_to_bvec(struct kunit *test) KUNIT_EXPECT_EQ(test, iter.count, 0); KUNIT_EXPECT_EQ(test, iter.nr_segs, 0); - /* Build the expected image in the scratch buffer. */ - patt = 0; - memset(scratch, 0, bufsize); - for (pr = bvec_test_ranges; pr->page >= 0; pr++) { - u8 *p = scratch + pr->page * PAGE_SIZE; - - for (i = pr->from; i < pr->to; i++) - p[i] = pattern(patt++); - } - + iov_kunit_build_to_reference_pattern(test, scratch, bufsize, bvec_test_ranges); iov_kunit_check_pattern(test, buffer, scratch, bufsize); KUNIT_SUCCEED(); } @@ -334,13 +328,12 @@ static void __init iov_kunit_copy_to_bvec(struct kunit *test) */ static void __init iov_kunit_copy_from_bvec(struct kunit *test) { - const struct iov_kunit_range *pr; struct iov_iter iter; struct bio_vec bvec[8]; struct page **spages, **bpages; u8 *scratch, *buffer; size_t bufsize, npages, size, copied; - int i, j; + int i; bufsize = 0x100000; npages = bufsize / PAGE_SIZE; @@ -362,20 +355,7 @@ static void __init iov_kunit_copy_from_bvec(struct kunit *test) KUNIT_EXPECT_EQ(test, iter.count, 0); KUNIT_EXPECT_EQ(test, iter.nr_segs, 0); - /* Build the expected image in the main buffer. */ - i = 0; - memset(buffer, 0, bufsize); - for (pr = bvec_test_ranges; pr->page >= 0; pr++) { - size_t patt = pr->page * PAGE_SIZE; - - for (j = pr->from; j < pr->to; j++) { - buffer[i++] = pattern(patt + j); - if (i >= bufsize) - goto stop; - } - } -stop: - + iov_kunit_build_from_reference_pattern(test, buffer, bufsize, bvec_test_ranges); iov_kunit_check_pattern(test, buffer, scratch, bufsize); KUNIT_SUCCEED(); }