From patchwork Thu Sep 14 22:15:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13386113 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 F166CEEAA7A for ; Thu, 14 Sep 2023 22:15:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 54FC66B02F8; Thu, 14 Sep 2023 18:15:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A93D6B02FA; Thu, 14 Sep 2023 18:15:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 25F2E6B02FB; Thu, 14 Sep 2023 18:15:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 1163C6B02F8 for ; Thu, 14 Sep 2023 18:15:47 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id DA668120664 for ; Thu, 14 Sep 2023 22:15:46 +0000 (UTC) X-FDA: 81236611092.13.C57C2AB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 2AF9810000D for ; Thu, 14 Sep 2023 22:15:45 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VadmL3fV; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.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=1694729745; 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=CMlwmXq8j0rs4LEdDpXfVHzrC0kRRfOaExs7WZepjuM=; b=OY63cq2ydJI/wbfcNfPjeR1rjzkGgmGgwK0atXqM4SLNBjYnKBoaWkNXyPvvhsSTQXLnHW dIO2SMmvWJqV4gfVlmeLSyXfIbolF3vJ+2hCOltEYh1VYocYbq0jIH8/f/x75JQbo8rHez vXdyOrE348/UYAwgEf8gAE2Tt4+/T50= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VadmL3fV; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.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=1694729745; a=rsa-sha256; cv=none; b=XJNSnTVAW6oFPddW1gSjO94mVxqFMi3OlfJY1o8YJf8HnO/hyav3JsqLChijSL499T4L2L pIIYtV2cSQq9FR7ZompW87y+gDnviVqNipXIWU076XHQpzGdNtlPij5rCoLO/8QbsoS2vW WUBodz53Nu5gULxE/CV0FRGOmaR4xTY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694729744; 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=CMlwmXq8j0rs4LEdDpXfVHzrC0kRRfOaExs7WZepjuM=; b=VadmL3fV+gDUy1LrOEQpM+6Sk+6CnLJG2fdCucG83FxI0cuFdaJO+veR8mRe3pGX+OCNR3 zc6bLA+k21f5R2dwU7W2UJcQgv0rK4P2AYSbrQwQEU0MTJt55uvC/qEN8V7O/i2ebLN52X FP7bpo2jh/NaNEYBEe3cwDR6dIkGlIc= 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-683-hhajP-8pPVuMhR_hSlZ2uQ-1; Thu, 14 Sep 2023 18:15:40 -0400 X-MC-Unique: hhajP-8pPVuMhR_hSlZ2uQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 8108F101A550; Thu, 14 Sep 2023 22:15:39 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B0877B62; Thu, 14 Sep 2023 22:15:37 +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 3/9] iov_iter: Consolidate the test vector struct in the kunit tests Date: Thu, 14 Sep 2023 23:15:20 +0100 Message-ID: <20230914221526.3153402-4-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.5 X-Rspamd-Queue-Id: 2AF9810000D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 1br8z1rzucnn5b5bwew69kn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VD3bd33WqjUxN9C/gaKhQA3XI+PzUbtMvTLFD9DxTl2xkp/SpMQtMNrSJLn23iVr7aG1qJVm41N2+Z83E/bLfkg9Lx0Eksu0w4dO5MdPUwlkQ7aLv6XzfqjpCgVi8qng6+cYmVrc4XAWdnl243CoDe5eVyWP2H50OAojwR3Rm/cwi96jOgiqCl94OVn0NR/AyYM7aauBAmYEZfi3LwYBRiEU4ncK1cYYRq/OVQVn7pFSuJ/2E/8swdKgWW9zj9/ZW6PFp9k9iTRnMKCTWOkG6CBCYxupoMtMFm4Fb740X2GZwj2ZKOFVpJaQS/OaiAaywyaZXiQzrVixGSofgTUQUTkbc5cqZcvVPc5GruE8fpB+6iG8ACUxTNM9FI9/joPrHlixm4KL3wuvEMdb4hJD7kRr3EEIFgTjISj1FjICtOC4DaaL7cuNyxBh+u 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: Consolidate the test vector struct in the kunit tests so that the bvec pattern check helpers can share with the kvec check helpers. 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 | 90 ++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/lib/kunit_iov_iter.c b/lib/kunit_iov_iter.c index ee586eb652b4..4925ca37cde6 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -18,22 +18,46 @@ MODULE_DESCRIPTION("iov_iter testing"); MODULE_AUTHOR("David Howells "); MODULE_LICENSE("GPL"); -struct kvec_test_range { +struct iov_kunit_range { int page, from, to; }; -static const struct kvec_test_range kvec_test_ranges[] = { - { 0, 0x00002, 0x00002 }, - { 0, 0x00027, 0x03000 }, - { 0, 0x05193, 0x18794 }, - { 0, 0x20000, 0x20000 }, - { 0, 0x20000, 0x24000 }, - { 0, 0x24000, 0x27001 }, - { 0, 0x29000, 0xffffb }, - { 0, 0xffffd, 0xffffe }, +/* + * Ranges that to use in tests where we have address/offset ranges to play + * with (ie. KVEC) or where we have a single blob that we can copy + * arbitrary chunks of (ie. XARRAY). + */ +static const struct iov_kunit_range kvec_test_ranges[] = { + { 0, 0x00002, 0x00002 }, /* Start with an empty range */ + { 0, 0x00027, 0x03000 }, /* Midpage to page end */ + { 0, 0x05193, 0x18794 }, /* Midpage to midpage */ + { 0, 0x20000, 0x20000 }, /* Empty range in the middle */ + { 0, 0x20000, 0x24000 }, /* Page start to page end */ + { 0, 0x24000, 0x27001 }, /* Page end to midpage */ + { 0, 0x29000, 0xffffb }, /* Page start to midpage */ + { 0, 0xffffd, 0xffffe }, /* Almost contig to last, ending in same page */ { -1 } }; +/* + * Ranges that to use in tests where we have a list of partial pages to + * play with (ie. BVEC). + */ +static const struct iov_kunit_range bvec_test_ranges[] = { + { 0, 0x0002, 0x0002 }, /* Start with an empty range */ + { 1, 0x0027, 0x0893 }, /* Random part of page */ + { 2, 0x0193, 0x0794 }, /* Random part of page */ + { 3, 0x0000, 0x1000 }, /* Full page */ + { 4, 0x0000, 0x1000 }, /* Full page logically contig to last */ + { 5, 0x0000, 0x1000 }, /* Full page logically contig to last */ + { 6, 0x0000, 0x0ffb }, /* Part page logically contig to last */ + { 6, 0x0ffd, 0x0ffe }, /* Part of prev page, but not quite contig */ + { -1 } +}; + +/* + * The pattern to fill with. + */ static inline u8 pattern(unsigned long x) { return x & 0xff; @@ -44,6 +68,9 @@ static void iov_kunit_unmap(void *data) vunmap(data); } +/* + * Create a buffer out of some pages and return a vmap'd pointer to it. + */ static void *__init iov_kunit_create_buffer(struct kunit *test, struct page ***ppages, size_t npages) @@ -75,7 +102,7 @@ static void *__init iov_kunit_create_buffer(struct kunit *test, */ static void iov_kunit_build_to_reference_pattern(struct kunit *test, u8 *scratch, size_t bufsize, - const struct kvec_test_range *pr) + const struct iov_kunit_range *pr) { int i, patt = 0; @@ -91,7 +118,7 @@ static void iov_kunit_build_to_reference_pattern(struct kunit *test, u8 *scratch */ static void iov_kunit_build_from_reference_pattern(struct kunit *test, u8 *buffer, size_t bufsize, - const struct kvec_test_range *pr) + const struct iov_kunit_range *pr) { size_t i = 0, j; @@ -124,7 +151,7 @@ static void __init iov_kunit_load_kvec(struct kunit *test, struct iov_iter *iter, int dir, struct kvec *kvec, unsigned int kvmax, void *buffer, size_t bufsize, - const struct kvec_test_range *pr) + const struct iov_kunit_range *pr) { size_t size = 0; int i; @@ -217,28 +244,12 @@ static void __init iov_kunit_copy_from_kvec(struct kunit *test) KUNIT_SUCCEED(); } -struct bvec_test_range { - int page, from, to; -}; - -static const struct bvec_test_range bvec_test_ranges[] = { - { 0, 0x0002, 0x0002 }, - { 1, 0x0027, 0x0893 }, - { 2, 0x0193, 0x0794 }, - { 3, 0x0000, 0x1000 }, - { 4, 0x0000, 0x1000 }, - { 5, 0x0000, 0x1000 }, - { 6, 0x0000, 0x0ffb }, - { 6, 0x0ffd, 0x0ffe }, - { -1 } -}; - static void __init iov_kunit_load_bvec(struct kunit *test, struct iov_iter *iter, int dir, struct bio_vec *bvec, unsigned int bvmax, struct page **pages, size_t npages, size_t bufsize, - const struct bvec_test_range *pr) + const struct iov_kunit_range *pr) { struct page *can_merge = NULL, *page; size_t size = 0; @@ -276,13 +287,13 @@ static void __init iov_kunit_load_bvec(struct kunit *test, */ static void __init iov_kunit_copy_to_bvec(struct kunit *test) { - const struct bvec_test_range *pr; + 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, b, patt; + int i, patt; bufsize = 0x100000; npages = bufsize / PAGE_SIZE; @@ -305,10 +316,9 @@ static void __init iov_kunit_copy_to_bvec(struct kunit *test) KUNIT_EXPECT_EQ(test, iter.nr_segs, 0); /* Build the expected image in the scratch buffer. */ - b = 0; patt = 0; memset(scratch, 0, bufsize); - for (pr = bvec_test_ranges; pr->page >= 0; pr++, b++) { + for (pr = bvec_test_ranges; pr->page >= 0; pr++) { u8 *p = scratch + pr->page * PAGE_SIZE; for (i = pr->from; i < pr->to; i++) @@ -324,7 +334,7 @@ static void __init iov_kunit_copy_to_bvec(struct kunit *test) */ static void __init iov_kunit_copy_from_bvec(struct kunit *test) { - const struct bvec_test_range *pr; + const struct iov_kunit_range *pr; struct iov_iter iter; struct bio_vec bvec[8]; struct page **spages, **bpages; @@ -411,7 +421,7 @@ static struct xarray *iov_kunit_create_xarray(struct kunit *test) */ static void __init iov_kunit_copy_to_xarray(struct kunit *test) { - const struct kvec_test_range *pr; + const struct iov_kunit_range *pr; struct iov_iter iter; struct xarray *xarray; struct page **spages, **bpages; @@ -457,7 +467,7 @@ static void __init iov_kunit_copy_to_xarray(struct kunit *test) */ static void __init iov_kunit_copy_from_xarray(struct kunit *test) { - const struct kvec_test_range *pr; + const struct iov_kunit_range *pr; struct iov_iter iter; struct xarray *xarray; struct page **spages, **bpages; @@ -503,7 +513,7 @@ static void __init iov_kunit_copy_from_xarray(struct kunit *test) */ static void __init iov_kunit_extract_pages_kvec(struct kunit *test) { - const struct kvec_test_range *pr; + const struct iov_kunit_range *pr; struct iov_iter iter; struct page **bpages, *pagelist[8], **pages = pagelist; struct kvec kvec[8]; @@ -583,7 +593,7 @@ static void __init iov_kunit_extract_pages_kvec(struct kunit *test) */ static void __init iov_kunit_extract_pages_bvec(struct kunit *test) { - const struct bvec_test_range *pr; + const struct iov_kunit_range *pr; struct iov_iter iter; struct page **bpages, *pagelist[8], **pages = pagelist; struct bio_vec bvec[8]; @@ -661,7 +671,7 @@ static void __init iov_kunit_extract_pages_bvec(struct kunit *test) */ static void __init iov_kunit_extract_pages_xarray(struct kunit *test) { - const struct kvec_test_range *pr; + const struct iov_kunit_range *pr; struct iov_iter iter; struct xarray *xarray; struct page **bpages, *pagelist[8], **pages = pagelist;