From patchwork Thu Sep 14 22:15:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13386111 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 0FA7BEEAA78 for ; Thu, 14 Sep 2023 22:15:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 805236B02E8; Thu, 14 Sep 2023 18:15:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B44F6B02E9; Thu, 14 Sep 2023 18:15:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 655426B02F6; Thu, 14 Sep 2023 18:15:41 -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 5049B6B02E8 for ; Thu, 14 Sep 2023 18:15:41 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2507D1CA18A for ; Thu, 14 Sep 2023 22:15:41 +0000 (UTC) X-FDA: 81236610882.04.710C073 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 704DD18001B for ; Thu, 14 Sep 2023 22:15:38 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ku8q+LFf; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.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=1694729738; 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=71Btu3XYwWZK+FmqHCgDmjFCfU/69a0+IvtQoWaiN/g=; b=wtn52NCItygLtP5BYT4rUan39gxIgAY+XtWpFQKzLnND4FVoQzD+PjpFtuUrniw+F67osO QNTgu4Aaravow1CLNCzgv8gZC/Yz2Bdl0DKWmbha6OpMmCeNc2Yqt1P6HLGYi5f1TBX+BU pXjBT+qp9wMt73xU6uAJbZZ2LC+z+hg= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ku8q+LFf; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.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=1694729738; a=rsa-sha256; cv=none; b=58F4RQIjmZvD72smBtoVZWV9w5Ji8FSkBEWZcXvH3bq5qDDIZOmKv8qBYqFffnx95fqg3b 154tOge0VfiWBdCP5zDXkJdIQNxycwcpsQBuDj5zRFLtCgTUf/cALYJ2Ea3ftV0i2ltQ9/ iLuUD6WisJ2dm7Tlj19WrdfqZNdwbec= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694729737; 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=71Btu3XYwWZK+FmqHCgDmjFCfU/69a0+IvtQoWaiN/g=; b=Ku8q+LFfY5xzlWUlePguhZr+JBhHZ3+i+Z86yCvX5fZ2wi3FaubilLgfmviTsiq9BkUaU+ qIDHTY5q+AUezEpXP2MmKum+A8dL1DB2O2iOVRakM8AieqWv7A/esBXoTd1jjb9LLbXTl8 xQsrmmWjWSWlV+maLrO7D3LZsfISWGM= 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-611-xSilx-EINMK-s9yGWPKnCA-1; Thu, 14 Sep 2023 18:15:34 -0400 X-MC-Unique: xSilx-EINMK-s9yGWPKnCA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 855E3857A9C; Thu, 14 Sep 2023 22:15:33 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2331E2026D4B; Thu, 14 Sep 2023 22:15:31 +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, Johannes Thumshirn , Christian Brauner , David Hildenbrand , John Hubbard Subject: [RFC PATCH 1/9] iov_iter: Fix some checkpatch complaints in kunit tests Date: Thu, 14 Sep 2023 23:15:18 +0100 Message-ID: <20230914221526.3153402-2-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.4 X-Rspamd-Queue-Id: 704DD18001B X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: qk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GFmFdqsmbQj8WyLEiAdpzgTfNLF8KwPAKkLgqJOQG+acduRJOHXygndr5AR3ktXHV/bxTiqQLz0E/PD/7zLxhf6IcUxsg17Z5Bg/HqZ00efv1D44jUdl28IEgZXM18Jb1Dh46USbcZik5IK7GWBBbnXgsSHz503le928TT4Y/aeCz6THfwpeJmbk8dSUY/glOErdqJfiuqo595EhbFIe/9vJJvCFHrJyEPRdWWyKgjse1mBCTYjvtD8rvfIqZDLUOCNZ7NT6H5CoorOGTuQuPIp0eixg02+Gtc/LyJOTqw8wjhIxS0Cd9p4LShJvCPq+65fAPlMc79wK4lVSzLCzVZcgDBnz88bcjbAuRp64pw84LpaNpOv2VAeaPUcmYNAuGB/WRdlkjTURRwr2fPSx+vwxRME046KVGhfqN0vpbm1t95OMo9Ats8VQglTofLnMfIGeqR2vHKIbbkAh4/Q0JVOaOcoipquN6Hm1uxL2wX4oHCCzGNDYrGJTqD5v4qC0+oBdPvQqhOSRQDGbA== 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: Fix some checkpatch complaints in the new iov_iter kunit tests: (1) Some lines had eight spaces instead of a tab at the start. (2) Checkpatch doesn't like (void*)(unsigned long)0xnnnnnULL, so switch to using POISON_POINTER_DELTA plus an offset instead. Reported-by: Johannes Thumshirn 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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/kunit_iov_iter.c b/lib/kunit_iov_iter.c index 859b67c4d697..4a6c0efd33f5 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -53,7 +53,7 @@ static void *__init iov_kunit_create_buffer(struct kunit *test, void *buffer; pages = kunit_kcalloc(test, npages, sizeof(struct page *), GFP_KERNEL); - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pages); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pages); *ppages = pages; got = alloc_pages_bulk_array(GFP_KERNEL, npages, pages); @@ -63,7 +63,7 @@ static void *__init iov_kunit_create_buffer(struct kunit *test, } buffer = vmap(pages, npages, VM_MAP | VM_MAP_PUT_PAGES, PAGE_KERNEL); - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buffer); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buffer); kunit_add_action_or_reset(test, iov_kunit_unmap, buffer); return buffer; @@ -548,7 +548,7 @@ static void __init iov_kunit_extract_pages_kvec(struct kunit *test) size_t offset0 = LONG_MAX; for (i = 0; i < ARRAY_SIZE(pagelist); i++) - pagelist[i] = (void *)(unsigned long)0xaa55aa55aa55aa55ULL; + pagelist[i] = (void *)POISON_POINTER_DELTA + 0x5a; len = iov_iter_extract_pages(&iter, &pages, 100 * 1024, ARRAY_SIZE(pagelist), 0, &offset0); @@ -626,7 +626,7 @@ static void __init iov_kunit_extract_pages_bvec(struct kunit *test) size_t offset0 = LONG_MAX; for (i = 0; i < ARRAY_SIZE(pagelist); i++) - pagelist[i] = (void *)(unsigned long)0xaa55aa55aa55aa55ULL; + pagelist[i] = (void *)POISON_POINTER_DELTA + 0x5a; len = iov_iter_extract_pages(&iter, &pages, 100 * 1024, ARRAY_SIZE(pagelist), 0, &offset0); @@ -709,7 +709,7 @@ static void __init iov_kunit_extract_pages_xarray(struct kunit *test) size_t offset0 = LONG_MAX; for (i = 0; i < ARRAY_SIZE(pagelist); i++) - pagelist[i] = (void *)(unsigned long)0xaa55aa55aa55aa55ULL; + pagelist[i] = (void *)POISON_POINTER_DELTA + 0x5a; len = iov_iter_extract_pages(&iter, &pages, 100 * 1024, ARRAY_SIZE(pagelist), 0, &offset0); From patchwork Thu Sep 14 22:15:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13386112 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 1F1F5EEAA78 for ; Thu, 14 Sep 2023 22:15:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A00BB6B02F6; Thu, 14 Sep 2023 18:15:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B0C96B02F8; Thu, 14 Sep 2023 18:15:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82A7D6B02FA; Thu, 14 Sep 2023 18:15:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 6EE4B6B02F6 for ; Thu, 14 Sep 2023 18:15:44 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 47A791206E9 for ; Thu, 14 Sep 2023 22:15:44 +0000 (UTC) X-FDA: 81236611008.15.0E9D71A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 8AF1F160011 for ; Thu, 14 Sep 2023 22:15:42 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=crh+LU4j; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.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=1694729742; 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=4ut+h9nLVtpMfUa14begCRaPNr+Lp71R8/RKDVqE44g=; b=E89XrXc0XpF5K+jgqUhSk9ZA+m34xI0wHaxBBw5BrMw6r9708trqetvMmwWmFPz5+Qq9fY 51ZNHaROnSxcx7CvhnMZuTVBJVIShxNhEo9DqVAa86aZWEcrGsS0sq/F1lgo+oIUFNZgIM esLCuIkgz1iZXKuCgPbTh2BiWjLl+UU= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=crh+LU4j; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.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=1694729742; a=rsa-sha256; cv=none; b=7ESJEeBzKj4W83kkeBwsfqHPWdDNTIH+xe3KrQsX6cTK5UoiR7YAEvCUXgl0EWzaagnO91 +fKE5zxg1Qm8qLSzwKqY5Av6uJ7HMIL4B72Xkn6CK3g2XSqks0gfjq4LOwmRwIm0QCtW02 qcXPy897/0M+oaSC359TNUwGrSMxCIE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694729741; 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=4ut+h9nLVtpMfUa14begCRaPNr+Lp71R8/RKDVqE44g=; b=crh+LU4juCMX/WjVoY3p+MRqWNm78wee9YKtN7yHYuaUHTgTJyMtYSXPlG9ovL1mMDGel4 UqM1qy1Wjgf40JqRQI4NBK4zdNWRqrBPxfZVZhZIfJyCGHe1xLFqz2wX+dJ1LuaAwh7Fzi 0Ij60NAoZCTdhy5I7F9UXXNPuxmxggA= 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-615-Dibw7jBuPtiY53bSfV_A_Q-1; Thu, 14 Sep 2023 18:15:37 -0400 X-MC-Unique: Dibw7jBuPtiY53bSfV_A_Q-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 9C577101B456; Thu, 14 Sep 2023 22:15:36 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D31410069B4; Thu, 14 Sep 2023 22:15:34 +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 2/9] iov_iter: Consolidate some of the repeated code into helpers Date: Thu, 14 Sep 2023 23:15:19 +0100 Message-ID: <20230914221526.3153402-3-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.3 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 8AF1F160011 X-Stat-Signature: rafm7rodfp1hg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ou8XQyGFnnPKcu6KE6rW9zUhW9w/eH8y6Ics1QIA9i9NohL/sVaAqL8cy3TtZobROIYQBkQIYYObkmTZ9xJHT0QEEIngQBLA4ubEcbPaD58aIXuurBpN+Dhjbt6tuuhE79k1q3L7AhOgPT3K42PXWrMIjurKDt/38i3sth+2JXNtXivZF8dA9oU2T6W9ZtInorTZa4cD8MDiE0kgIycyk2/VDJRbwH61grG3wY9mfF4lEqgj1wUO/fv4lxC6t99KQ2IFdDmlouJk2fkN1zEr6933MBXRQNJdxqlELaLSK7gFLmlW6reMfN404Jphvf9uo89vr/r1j+Kz0BdAvlpeJzE4XhrL5FUnaorR1mNHI7Gn96s3geEN8R/Y8ddSP8bGJyWzCjqeY4mmELOPoO6orqV1BjRbQ7RzEoOQoHCtZ0D/JzMRiab+w5DxLNFSTnUVZ3k1u/nnPPzAZYQ6JtAqn60v7Wf9z4SMBmOqfQm 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 some of the repeated code snippets into helper functions to reduce the line count. 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 | 189 +++++++++++++++++++------------------------ 1 file changed, 84 insertions(+), 105 deletions(-) diff --git a/lib/kunit_iov_iter.c b/lib/kunit_iov_iter.c index 4a6c0efd33f5..ee586eb652b4 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -19,18 +19,18 @@ MODULE_AUTHOR("David Howells "); MODULE_LICENSE("GPL"); struct kvec_test_range { - int from, to; + int page, from, to; }; static const struct kvec_test_range kvec_test_ranges[] = { - { 0x00002, 0x00002 }, - { 0x00027, 0x03000 }, - { 0x05193, 0x18794 }, - { 0x20000, 0x20000 }, - { 0x20000, 0x24000 }, - { 0x24000, 0x27001 }, - { 0x29000, 0xffffb }, - { 0xffffd, 0xffffe }, + { 0, 0x00002, 0x00002 }, + { 0, 0x00027, 0x03000 }, + { 0, 0x05193, 0x18794 }, + { 0, 0x20000, 0x20000 }, + { 0, 0x20000, 0x24000 }, + { 0, 0x24000, 0x27001 }, + { 0, 0x29000, 0xffffb }, + { 0, 0xffffd, 0xffffe }, { -1 } }; @@ -69,6 +69,57 @@ static void *__init iov_kunit_create_buffer(struct kunit *test, return buffer; } +/* + * Build the reference pattern in the scratch buffer that we expect to see in + * the iterator buffer (ie. the result of copy *to*). + */ +static void iov_kunit_build_to_reference_pattern(struct kunit *test, u8 *scratch, + size_t bufsize, + const struct kvec_test_range *pr) +{ + int i, patt = 0; + + memset(scratch, 0, bufsize); + for (; pr->page >= 0; pr++) + for (i = pr->from; i < pr->to; i++) + scratch[i] = pattern(patt++); +} + +/* + * Build the reference pattern in the iterator buffer that we expect to see in + * the scratch buffer (ie. the result of copy *from*). + */ +static void iov_kunit_build_from_reference_pattern(struct kunit *test, u8 *buffer, + size_t bufsize, + const struct kvec_test_range *pr) +{ + size_t i = 0, j; + + memset(buffer, 0, bufsize); + for (; pr->page >= 0; pr++) { + for (j = pr->from; j < pr->to; j++) { + buffer[i++] = pattern(j); + if (i >= bufsize) + return; + } + } +} + +/* + * Compare two kernel buffers to see that they're the same. + */ +static void iov_kunit_check_pattern(struct kunit *test, const u8 *buffer, + const u8 *scratch, size_t bufsize) +{ + size_t i; + + for (i = 0; i < bufsize; i++) { + KUNIT_EXPECT_EQ_MSG(test, buffer[i], scratch[i], "at i=%x", i); + if (buffer[i] != scratch[i]) + return; + } +} + static void __init iov_kunit_load_kvec(struct kunit *test, struct iov_iter *iter, int dir, struct kvec *kvec, unsigned int kvmax, @@ -79,7 +130,7 @@ static void __init iov_kunit_load_kvec(struct kunit *test, int i; for (i = 0; i < kvmax; i++, pr++) { - if (pr->from < 0) + if (pr->page < 0) break; KUNIT_ASSERT_GE(test, pr->to, pr->from); KUNIT_ASSERT_LE(test, pr->to, bufsize); @@ -97,13 +148,12 @@ static void __init iov_kunit_load_kvec(struct kunit *test, */ static void __init iov_kunit_copy_to_kvec(struct kunit *test) { - const struct kvec_test_range *pr; struct iov_iter iter; struct page **spages, **bpages; struct kvec kvec[8]; u8 *scratch, *buffer; size_t bufsize, npages, size, copied; - int i, patt; + int i; bufsize = 0x100000; npages = bufsize / PAGE_SIZE; @@ -125,20 +175,8 @@ static void __init iov_kunit_copy_to_kvec(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 = kvec_test_ranges; pr->from >= 0; pr++) - for (i = pr->from; i < pr->to; i++) - scratch[i] = pattern(patt++); - - /* Compare the images */ - for (i = 0; i < bufsize; i++) { - KUNIT_EXPECT_EQ_MSG(test, buffer[i], scratch[i], "at i=%x", i); - if (buffer[i] != scratch[i]) - return; - } - + iov_kunit_build_to_reference_pattern(test, scratch, bufsize, kvec_test_ranges); + iov_kunit_check_pattern(test, buffer, scratch, bufsize); KUNIT_SUCCEED(); } @@ -147,13 +185,12 @@ static void __init iov_kunit_copy_to_kvec(struct kunit *test) */ static void __init iov_kunit_copy_from_kvec(struct kunit *test) { - const struct kvec_test_range *pr; struct iov_iter iter; struct page **spages, **bpages; struct kvec kvec[8]; u8 *scratch, *buffer; size_t bufsize, npages, size, copied; - int i, j; + int i; bufsize = 0x100000; npages = bufsize / PAGE_SIZE; @@ -175,25 +212,8 @@ static void __init iov_kunit_copy_from_kvec(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 = kvec_test_ranges; pr->from >= 0; pr++) { - for (j = pr->from; j < pr->to; j++) { - buffer[i++] = pattern(j); - if (i >= bufsize) - goto stop; - } - } -stop: - - /* Compare the images */ - for (i = 0; i < bufsize; i++) { - KUNIT_EXPECT_EQ_MSG(test, scratch[i], buffer[i], "at i=%x", i); - if (scratch[i] != buffer[i]) - return; - } - + iov_kunit_build_from_reference_pattern(test, buffer, bufsize, kvec_test_ranges); + iov_kunit_check_pattern(test, buffer, scratch, bufsize); KUNIT_SUCCEED(); } @@ -210,7 +230,7 @@ static const struct bvec_test_range bvec_test_ranges[] = { { 5, 0x0000, 0x1000 }, { 6, 0x0000, 0x0ffb }, { 6, 0x0ffd, 0x0ffe }, - { -1, -1, -1 } + { -1 } }; static void __init iov_kunit_load_bvec(struct kunit *test, @@ -225,7 +245,7 @@ static void __init iov_kunit_load_bvec(struct kunit *test, int i; for (i = 0; i < bvmax; i++, pr++) { - if (pr->from < 0) + if (pr->page < 0) break; KUNIT_ASSERT_LT(test, pr->page, npages); KUNIT_ASSERT_LT(test, pr->page * PAGE_SIZE, bufsize); @@ -288,20 +308,14 @@ static void __init iov_kunit_copy_to_bvec(struct kunit *test) b = 0; patt = 0; memset(scratch, 0, bufsize); - for (pr = bvec_test_ranges; pr->from >= 0; pr++, b++) { + for (pr = bvec_test_ranges; pr->page >= 0; pr++, b++) { u8 *p = scratch + pr->page * PAGE_SIZE; for (i = pr->from; i < pr->to; i++) p[i] = pattern(patt++); } - /* Compare the images */ - for (i = 0; i < bufsize; i++) { - KUNIT_EXPECT_EQ_MSG(test, buffer[i], scratch[i], "at i=%x", i); - if (buffer[i] != scratch[i]) - return; - } - + iov_kunit_check_pattern(test, buffer, scratch, bufsize); KUNIT_SUCCEED(); } @@ -341,7 +355,7 @@ static void __init iov_kunit_copy_from_bvec(struct kunit *test) /* Build the expected image in the main buffer. */ i = 0; memset(buffer, 0, bufsize); - for (pr = bvec_test_ranges; pr->from >= 0; pr++) { + for (pr = bvec_test_ranges; pr->page >= 0; pr++) { size_t patt = pr->page * PAGE_SIZE; for (j = pr->from; j < pr->to; j++) { @@ -352,13 +366,7 @@ static void __init iov_kunit_copy_from_bvec(struct kunit *test) } stop: - /* Compare the images */ - for (i = 0; i < bufsize; i++) { - KUNIT_EXPECT_EQ_MSG(test, scratch[i], buffer[i], "at i=%x", i); - if (scratch[i] != buffer[i]) - return; - } - + iov_kunit_check_pattern(test, buffer, scratch, bufsize); KUNIT_SUCCEED(); } @@ -409,7 +417,7 @@ static void __init iov_kunit_copy_to_xarray(struct kunit *test) struct page **spages, **bpages; u8 *scratch, *buffer; size_t bufsize, npages, size, copied; - int i, patt; + int i; bufsize = 0x100000; npages = bufsize / PAGE_SIZE; @@ -426,7 +434,7 @@ static void __init iov_kunit_copy_to_xarray(struct kunit *test) iov_kunit_load_xarray(test, &iter, READ, xarray, bpages, npages); i = 0; - for (pr = kvec_test_ranges; pr->from >= 0; pr++) { + for (pr = kvec_test_ranges; pr->page >= 0; pr++) { size = pr->to - pr->from; KUNIT_ASSERT_LE(test, pr->to, bufsize); @@ -439,20 +447,8 @@ static void __init iov_kunit_copy_to_xarray(struct kunit *test) i += size; } - /* Build the expected image in the scratch buffer. */ - patt = 0; - memset(scratch, 0, bufsize); - for (pr = kvec_test_ranges; pr->from >= 0; pr++) - for (i = pr->from; i < pr->to; i++) - scratch[i] = pattern(patt++); - - /* Compare the images */ - for (i = 0; i < bufsize; i++) { - KUNIT_EXPECT_EQ_MSG(test, buffer[i], scratch[i], "at i=%x", i); - if (buffer[i] != scratch[i]) - return; - } - + iov_kunit_build_to_reference_pattern(test, scratch, bufsize, kvec_test_ranges); + iov_kunit_check_pattern(test, buffer, scratch, bufsize); KUNIT_SUCCEED(); } @@ -467,7 +463,7 @@ static void __init iov_kunit_copy_from_xarray(struct kunit *test) struct page **spages, **bpages; u8 *scratch, *buffer; size_t bufsize, npages, size, copied; - int i, j; + int i; bufsize = 0x100000; npages = bufsize / PAGE_SIZE; @@ -484,7 +480,7 @@ static void __init iov_kunit_copy_from_xarray(struct kunit *test) iov_kunit_load_xarray(test, &iter, READ, xarray, bpages, npages); i = 0; - for (pr = kvec_test_ranges; pr->from >= 0; pr++) { + for (pr = kvec_test_ranges; pr->page >= 0; pr++) { size = pr->to - pr->from; KUNIT_ASSERT_LE(test, pr->to, bufsize); @@ -497,25 +493,8 @@ static void __init iov_kunit_copy_from_xarray(struct kunit *test) i += size; } - /* Build the expected image in the main buffer. */ - i = 0; - memset(buffer, 0, bufsize); - for (pr = kvec_test_ranges; pr->from >= 0; pr++) { - for (j = pr->from; j < pr->to; j++) { - buffer[i++] = pattern(j); - if (i >= bufsize) - goto stop; - } - } -stop: - - /* Compare the images */ - for (i = 0; i < bufsize; i++) { - KUNIT_EXPECT_EQ_MSG(test, scratch[i], buffer[i], "at i=%x", i); - if (scratch[i] != buffer[i]) - return; - } - + iov_kunit_build_from_reference_pattern(test, buffer, bufsize, kvec_test_ranges); + iov_kunit_check_pattern(test, buffer, scratch, bufsize); KUNIT_SUCCEED(); } @@ -573,7 +552,7 @@ static void __init iov_kunit_extract_pages_kvec(struct kunit *test) while (from == pr->to) { pr++; from = pr->from; - if (from < 0) + if (pr->page < 0) goto stop; } ix = from / PAGE_SIZE; @@ -651,7 +630,7 @@ static void __init iov_kunit_extract_pages_bvec(struct kunit *test) while (from == pr->to) { pr++; from = pr->from; - if (from < 0) + if (pr->page < 0) goto stop; } ix = pr->page + from / PAGE_SIZE; @@ -698,7 +677,7 @@ static void __init iov_kunit_extract_pages_xarray(struct kunit *test) iov_kunit_create_buffer(test, &bpages, npages); iov_kunit_load_xarray(test, &iter, READ, xarray, bpages, npages); - for (pr = kvec_test_ranges; pr->from >= 0; pr++) { + for (pr = kvec_test_ranges; pr->page >= 0; pr++) { from = pr->from; size = pr->to - from; KUNIT_ASSERT_LE(test, pr->to, bufsize); 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: 1br8z1rzucnn5b5bwew69knd68w3d8jn X-HE-Tag: 1694729745-911545 X-HE-Meta: U2FsdGVkX1/shmwjfqE4u5dkxvgu56pUecdGdQA3hLN9JmIna1t8FhrHhPviQiwQoO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dO5MdPUwlkQ7aLv6XzfqjpCgVi8qng6+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; 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: ygpzgcb11ycxo8s5pdwop4n9reyhjzgu X-HE-Tag: 1694729747-230714 X-HE-Meta: U2FsdGVkX1/vEmp4n5UCYUcc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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(); } From patchwork Thu Sep 14 22:15:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13386115 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 BADCCEEAA78 for ; Thu, 14 Sep 2023 22:15:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 520E66B02FE; Thu, 14 Sep 2023 18:15:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4CE8A6B02FF; Thu, 14 Sep 2023 18:15:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 348D46B0300; Thu, 14 Sep 2023 18:15:55 -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 20E846B02FE for ; Thu, 14 Sep 2023 18:15:55 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id EC0031604A4 for ; Thu, 14 Sep 2023 22:15:54 +0000 (UTC) X-FDA: 81236611428.04.D3BB665 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 0755D40026 for ; Thu, 14 Sep 2023 22:15:52 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fQLQeTt1; spf=pass (imf27.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694729753; 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=eHrqy9IhQqFP0qCYLkZt7PDlpPSTO0DMl+tDr5r7Ons=; b=Z0LRCwe3FOMoepKqlFxSMUGE9yOLkAjvyvjEsqxdX5vyphD83Xz3qug/WPaVvTSoDaUTLj pqS4z+vTSUS4hTw1EgbWTGDBFkDtnT+LczDCiW85KGZXT3QskXyrKogRGfU10iF9Qg5gCr 659fN14e2VX+RgrMGnj+uGvS4Lt/qOk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694729753; a=rsa-sha256; cv=none; b=rtw6tJDKfkZqsBakXOCrnNn3kt2YrkQnEh3jJ1QyMlL3KBIlaK6EB04zD4oe+FbxSVIxT0 oXSyNMObZozKy7M5htVg5B+S2a4jojKlslkdkDtphqRkiYdBHhscHYz4kG6A3PSJmyQkRk k42+3xG+mEw/PpruLdfqoQ5tlBU7hIY= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fQLQeTt1; spf=pass (imf27.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694729752; 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=eHrqy9IhQqFP0qCYLkZt7PDlpPSTO0DMl+tDr5r7Ons=; b=fQLQeTt1wvCiDy2hSNzIzqsrfgzrq73uohh4Bbq2idWfITPUwrklVUFFcLCarC7iyKf3Zb h/Lt0G5WB59zl+Q0NVwCqXyZxRr2biQBIIEqxQHbSMFKrV1se/c0axkzOj6HKsOgRxmKpg glbs705VarGOBFwkj+A+Q/ukEHL0MXQ= 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-34-9PaOd7xYNiK2Xp_5jAMWLQ-1; Thu, 14 Sep 2023 18:15:46 -0400 X-MC-Unique: 9PaOd7xYNiK2Xp_5jAMWLQ-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 8AE86802D35; Thu, 14 Sep 2023 22:15:45 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3180E10EA0; Thu, 14 Sep 2023 22:15:43 +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, Andrew Morton , Christian Brauner , David Hildenbrand , John Hubbard Subject: [RFC PATCH 5/9] iov_iter: Create a function to prepare userspace VM for UBUF/IOVEC tests Date: Thu, 14 Sep 2023 23:15:22 +0100 Message-ID: <20230914221526.3153402-6-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: 0755D40026 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: hzeaz7hrjn5jzwkhbxjtodyhd176b4dy X-HE-Tag: 1694729752-919793 X-HE-Meta: U2FsdGVkX19PlvohCpT5tDAQe3Welf0TkC7tPuoVHAMi3IkcXt4xffrkE4Dym3a++VXH1h8xWdCn6ktql7TqPftpM9bDJCkfisj9m/wCYLCC2gTp6kKxfIOb4QgPBgtpnY5uPC0bGDwWIxWsKqtrnAfyuCc9PWClvHC1lmmgVS3jlnX6dtDhAGIIdzwxHMjiAbXtASWIfxVIGNSEcADYg7hw8zysLrDeARPRM+YKk22kizIEgscz8Lgyx06iOkP426apuCGM3qhMlPEyMrKGjxzlRvNML+AncZ/0G0pQZmCAbSFKj0dTzbjKzeQDztMiVshk5FYp9S7yNkOUnnJaGGKRaGH2OsWP8h55WnJ/qNiMgD6Lo9RogB+AEHk8bC8Hs4X6aF3kshWMpZU1EGAcBY8sZHVrEngr/futDpXxwwHMDCELhfxlMv1hy3qeXC6+0gp/Jk0I0VlvsOJcZBy2XPInWgn2KqJgHFk0HSO3/SQ+mz1LFggCG+j7/eA54kuOK3LNZGYDujjOlBf1TOChfETLfSvKlCYTtrYupHzsmHG9oNRD3APpNcgcmcEzjc9IENnUDvA3KRSpgb5sDkbYNI26HcPYnpsIU+lOAApgBQBMk2Cn2ATKo3bRbdM8+u3Izjfph1uKBA2q991k9+KJVsQUIH2aRhE8ehQYeqBIlosQb3fPX/KMtyf5Ugv+Im7zekgh6xCCEMNfvvN+VpKc7y89bjIaomK1IAPBZKiUaoXeyJu7vaKk3ZIWXSfFgCWvvu/DMh/UttVjOJ/RyI1F8lpburNLT5K91MUWX7pVIJiKb4rhCrEch0e+h7osCjPA9ehZxZ54iPuMKGiOSjeH3wN3BWxr8PnxlnsfrcKQHMUNabO7xCdDye7GMZ3WgSQXJVEsATREqgeiyMSHvfaHGKQbzq9odasARd+OZ1Kj8+iB/2BMzO4/geQoFHy4EgVdHDe36vSk9d1KPLIg3Ej QL233uwP S//8T/XOr+nTmqu8x0duxnruaJYN/01v1Uaei7o7/d+lmNNdFKQCBjTNjGc70xtgQd1lPmACcwcvc1wTKPasxpOWvNkU+Zt2c1AWPamd7d9qYswMtc2JF7ZAhKdMAzrfCEsHFoSpiKOMIeFi1PycoPqv+06oNstnSLPOGWu/6L/ecTIbA/lL03zMM/HOurePVOFRC8fM6RAV00aKt9T9NB/G4HNs7YISk79sbm5SlFd33tKNcVcHFpL6wSTA5+x+V7gmyRN4ETHaxfoWPxhMg8ea1cnBg+2IZHcnCrL3/B164tAoH8jjRdRxSbCvt1tMCcj4/UmYoLEEwM7K7HW83s4uocrSJ6bQf7rUA/+3BR2uvZPlGhbeqWIvrgtkzmN0zzMb0Ck9uoqycsflp5KSCz7uICdP93hKrm8sO4axiGViVV8dEKyqO5FW9T2SpJjSIlAT0WQO8vpfd78ciRUBt6VnTSTFBcgfGWw+9FuAsTBbQ5uYDn2hYRRTvX7g9uVVOAf3qZBCrGd4Bc5k1tCIg2Q1mxUT0P5GExa8nw+kvisEecjRmRQy2WCgKgnEBu9OTyPdy6UwHj8VLL5qDzDkw7oC0oexK/Yw5IePVkjWoEr+iuXsm4fJCqjvfpcgEGsw1/xi/B0Pt0lhslBk8U3+8Ll3+Xv9N5l7m0ThNLsr8JzX/7xUo9wnSZRfbgA== 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: Create a function to set up a userspace VM for the kunit testing thread and set up a buffer within it such that ITER_UBUF and ITER_IOVEC tests can be performed. Note that this requires current->mm to point to a sufficiently set up mm_struct. This is done by partially mirroring what execve does. The following steps are performed: (1) Allocate an mm_struct and pick an arch layout (required to set mm->get_unmapped_area). (2) Create an empty "stack" VMA so that the VMA maple tree is set up and won't cause a crash in the maple tree code later. We don't actually care about the stack as we're not going to actually execute userspace. (3) Create an anon file and attach a bunch of folios to it so that the requested number of pages are accessible. (4) Make the kthread use the mm. This must be done before mmap is called. (5) Shared-mmap the anon file into the allocated mm_struct. This requires access to otherwise unexported core symbols: mm_alloc(), vm_area_alloc(), insert_vm_struct() arch_pick_mmap_layout() and anon_inode_getfile_secure(), which I've exported _GPL. [?] Would it be better if this were done in core and not in a module? Signed-off-by: David Howells cc: Andrew Morton cc: Christoph Hellwig cc: Christian Brauner cc: Jens Axboe cc: Al Viro cc: Matthew Wilcox cc: David Hildenbrand cc: John Hubbard cc: Brendan Higgins cc: David Gow cc: linux-mm@kvack.org cc: linux-fsdevel@vger.kernel.org cc: linux-kselftest@vger.kernel.org cc: kunit-dev@googlegroups.com --- fs/anon_inodes.c | 1 + kernel/fork.c | 2 + lib/kunit_iov_iter.c | 158 +++++++++++++++++++++++++++++++++++++++++++ mm/mmap.c | 1 + mm/util.c | 1 + 5 files changed, 163 insertions(+) diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c index 24192a7667ed..4190336180ee 100644 --- a/fs/anon_inodes.c +++ b/fs/anon_inodes.c @@ -176,6 +176,7 @@ struct file *anon_inode_getfile_secure(const char *name, return __anon_inode_getfile(name, fops, priv, flags, context_inode, true); } +EXPORT_SYMBOL_GPL(anon_inode_getfile_secure); static int __anon_inode_getfd(const char *name, const struct file_operations *fops, diff --git a/kernel/fork.c b/kernel/fork.c index 3b6d20dfb9a8..9ab604574400 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -494,6 +494,7 @@ struct vm_area_struct *vm_area_alloc(struct mm_struct *mm) return vma; } +EXPORT_SYMBOL_GPL(vm_area_alloc); struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) { @@ -1337,6 +1338,7 @@ struct mm_struct *mm_alloc(void) memset(mm, 0, sizeof(*mm)); return mm_init(mm, current, current_user_ns()); } +EXPORT_SYMBOL_GPL(mm_alloc); static inline void __mmput(struct mm_struct *mm) { diff --git a/lib/kunit_iov_iter.c b/lib/kunit_iov_iter.c index eb86371b67d0..3353bca9c40f 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -10,6 +10,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include #include #include @@ -68,6 +74,20 @@ static void iov_kunit_unmap(void *data) vunmap(data); } +static void iov_kunit_mmdrop(void *data) +{ + struct mm_struct *mm = data; + + if (current->mm == mm) + kthread_unuse_mm(mm); + mmdrop(mm); +} + +static void iov_kunit_fput(void *data) +{ + fput(data); +} + /* * Create a buffer out of some pages and return a vmap'd pointer to it. */ @@ -96,6 +116,20 @@ static void *__init iov_kunit_create_buffer(struct kunit *test, return buffer; } +static void iov_kunit_fill_user_buf(struct kunit *test, + u8 __user *buffer, size_t bufsize) +{ + size_t i; + int err; + + for (i = 0; i < bufsize; i++) { + err = put_user(pattern(i), &buffer[i]); + KUNIT_EXPECT_EQ(test, err, 0); + if (test->status == KUNIT_FAILURE) + return; + } +} + /* * Build the reference pattern in the scratch buffer that we expect to see in * the iterator buffer (ie. the result of copy *to*). @@ -151,6 +185,130 @@ static void iov_kunit_check_pattern(struct kunit *test, const u8 *buffer, } } +/* + * Compare a user and a scratch buffer to see that they're the same. + */ +static void iov_kunit_check_user_pattern(struct kunit *test, const u8 __user *buffer, + const u8 *scratch, size_t bufsize) +{ + size_t i; + int err; + u8 c; + + for (i = 0; i < bufsize; i++) { + err = get_user(c, &buffer[i]); + KUNIT_EXPECT_EQ(test, err, 0); + KUNIT_EXPECT_EQ_MSG(test, c, scratch[i], "at i=%x", i); + if (c != scratch[i]) + return; + } +} + +static const struct file_operations iov_kunit_user_file_fops = { + .mmap = generic_file_mmap, +}; + +static int iov_kunit_user_file_read_folio(struct file *file, struct folio *folio) +{ + folio_mark_uptodate(folio); + folio_unlock(folio); + return 0; +} + +static const struct address_space_operations iov_kunit_user_file_aops = { + .read_folio = iov_kunit_user_file_read_folio, + .dirty_folio = filemap_dirty_folio, +}; + +/* + * Create an anonymous file and attach a bunch of pages to it. We can then use + * this in mmap() and check the pages against it when doing extraction tests. + */ +static struct file *iov_kunit_create_file(struct kunit *test, size_t npages, + struct page ***ppages) +{ + struct folio *folio; + struct file *file; + struct page **pages = NULL; + size_t i; + + if (ppages) { + pages = kunit_kcalloc(test, npages, sizeof(struct page *), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pages); + *ppages = pages; + } + + file = anon_inode_getfile_secure("kunit-iov-test", + &iov_kunit_user_file_fops, + NULL, O_RDWR, NULL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, file); + kunit_add_action_or_reset(test, iov_kunit_fput, file); + file->f_mapping->a_ops = &iov_kunit_user_file_aops; + + i_size_write(file_inode(file), npages * PAGE_SIZE); + for (i = 0; i < npages; i++) { + folio = filemap_grab_folio(file->f_mapping, i); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, folio); + if (pages) + *pages++ = folio_page(folio, 0); + folio_unlock(folio); + folio_put(folio); + } + + return file; +} + +static u8 __user *__init iov_kunit_create_user_buf(struct kunit *test, + size_t npages, + struct page ***ppages) +{ + struct rlimit rlim_stack = { + .rlim_cur = LONG_MAX, + .rlim_max = LONG_MAX, + }; + struct vm_area_struct *vma; + struct mm_struct *mm; + struct file *file; + u8 __user *buffer; + int ret; + + KUNIT_ASSERT_NULL(test, current->mm); + + mm = mm_alloc(); + KUNIT_ASSERT_NOT_NULL(test, mm); + kunit_add_action_or_reset(test, iov_kunit_mmdrop, mm); + arch_pick_mmap_layout(mm, &rlim_stack); + + vma = vm_area_alloc(mm); + KUNIT_ASSERT_NOT_NULL(test, vma); + vma_set_anonymous(vma); + + /* + * Place the stack at the largest stack address the architecture + * supports. Later, we'll move this to an appropriate place. We don't + * use STACK_TOP because that can depend on attributes which aren't + * configured yet. + */ + vma->vm_end = STACK_TOP_MAX; + vma->vm_start = vma->vm_end - PAGE_SIZE; + vm_flags_init(vma, VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP); + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); + + ret = insert_vm_struct(mm, vma); + KUNIT_ASSERT_EQ(test, ret, 0); + + mm->stack_vm = mm->total_vm = 1; + + file = iov_kunit_create_file(test, npages, ppages); + + kthread_use_mm(mm); + buffer = (u8 __user *)vm_mmap(file, 0, PAGE_SIZE * npages, + PROT_READ | PROT_WRITE, + MAP_SHARED, 0); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buffer); + return buffer; +} + static void __init iov_kunit_load_kvec(struct kunit *test, struct iov_iter *iter, int dir, struct kvec *kvec, unsigned int kvmax, diff --git a/mm/mmap.c b/mm/mmap.c index b56a7f0c9f85..2ea4a98a2cab 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3284,6 +3284,7 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma) return 0; } +EXPORT_SYMBOL_GPL(insert_vm_struct); /* * Copy the vma structure to a new location in the same mm, diff --git a/mm/util.c b/mm/util.c index 8cbbfd3a3d59..a393a308607c 100644 --- a/mm/util.c +++ b/mm/util.c @@ -455,6 +455,7 @@ void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) mm->get_unmapped_area = arch_get_unmapped_area; } #endif +EXPORT_SYMBOL_GPL(arch_pick_mmap_layout); /** * __account_locked_vm - account locked pages to an mm's locked_vm From patchwork Thu Sep 14 22:15:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13386116 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 79E57EEAA7A for ; Thu, 14 Sep 2023 22:15:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC4C86B02FF; Thu, 14 Sep 2023 18:15:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A76E36B0300; Thu, 14 Sep 2023 18:15:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8CA226B0301; Thu, 14 Sep 2023 18:15:56 -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 74CC06B02FF for ; Thu, 14 Sep 2023 18:15:56 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 52FC6A0673 for ; Thu, 14 Sep 2023 22:15:56 +0000 (UTC) X-FDA: 81236611512.14.1E054EF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 8774A180015 for ; Thu, 14 Sep 2023 22:15:54 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FwxgI61O; spf=pass (imf24.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694729754; a=rsa-sha256; cv=none; b=8h08W3QjtxDhjyfyt6IrJQTlzEqhwxDF/2Nemn0K9uI8AL7e4BMKmQB3Q0Spiutno/b+n9 NPnVAXzOVmVGeMRmzFuEXazJsh1O3EUm1YSKFnUK2377cEHCcjj33ayyLggp7JGXDv1sph DMnifgBNgNBLvPF7ukisTKZsaxGF9pM= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FwxgI61O; spf=pass (imf24.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694729754; 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=VtAwaM2B3p8HaWMuYOi3rMk0MQyqz+yXDmdiAqy5Wgk=; b=fZQ84qp4YTavrk7Vtq5ebeTrK1GsE8hnFiYotNHRdlc6Wy6XG6tcaiXwR/9ZSyHt5wRa7I QeDooku4F3uefrMdRx5QwppqBskp3hn/UaRs7DhbsLz5oJIwAxv1Cr0VSLiq5kfA54f6mq PZHAyV2kzEp3qPxQwBhV6agMNv1j2MA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694729753; 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=VtAwaM2B3p8HaWMuYOi3rMk0MQyqz+yXDmdiAqy5Wgk=; b=FwxgI61OpNqLH1RnevRMqeFzHrhEodcO37VpG1CcURwOR0bm1kR5lK3/SzH6RhLb8SDTJU ssHs3mFgoxPmMgAIua/LyxS6oP/uyewzxIoQsHJ1gtIDenY0vXSTOMidWsoBjrgSp5vKzA TuhGuBIQNMQrPoDrDTcpLQUakJsL4eY= 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-680-F6lxP1o9O8qZVNHtllb3dg-1; Thu, 14 Sep 2023 18:15:49 -0400 X-MC-Unique: F6lxP1o9O8qZVNHtllb3dg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 CDD9D800159; Thu, 14 Sep 2023 22:15:48 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5DF992156A27; Thu, 14 Sep 2023 22:15:46 +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, Andrew Morton , Christian Brauner , David Hildenbrand , John Hubbard Subject: [RFC PATCH 6/9] iov_iter: Add copy kunit tests for ITER_UBUF and ITER_IOVEC Date: Thu, 14 Sep 2023 23:15:23 +0100 Message-ID: <20230914221526.3153402-7-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.6 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 8774A180015 X-Stat-Signature: icy54ij6e5bg8nsrp4u8dax6nrg74u7y X-Rspam-User: X-HE-Tag: 1694729754-561301 X-HE-Meta: U2FsdGVkX19Tp39bZPSYXMcEnhEMWsdZMbJsnBFlya6HBIVo8rYFLZ09mjzYTtPBvJrPVZjmH8/Cl6hC2dP/NpYO8PYFtF4vsxafpUq/cTy4ajh+94JSqK369EMMDYt5CtHv98uz3wocUxDqwcYiAiBGGplLL1IZLVSM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GD7Lxe2dBtL9fck5lyZ07CUnfPrhA1Qm1EWLu9QWoRbfZHgevkS5aHX2OF2yz3fOlpaeT48K8eMW6u0soEF4zlptMbu1LIgeKu3XmGDu9DpSq1ZwF/TrtOS4qPyxuq+Ar9tei9++3Rxcib3XO+En+hQdB1n6S3i3Osabjp2zxeGZ6y5bWdiWYNGtTN1CNHobrKWhhD8NyZAc5AVZB87Z3314o/TReK6vQ/YNQiK+SjA9RQTaSvAjY1LUlJjUJynMHx64ns2x4uVNPTqB1xE+dCZuCVOz97KaV4V9Tr66BRr9FSQIA0KLbcDf7jLnzOjFrGkAWYqkbWJgQLe0bIzZ524vJzyWjI3utLwh/B0XZjLt54oMOXVB48w9V+HrBuCs2jQ== 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 copy kunit tests for ITER_UBUF- and ITER_IOVEC-type iterators. This attaches a userspace VM with a mapped file in it temporarily to the test thread. Signed-off-by: David Howells cc: Andrew Morton cc: Christoph Hellwig cc: Christian Brauner cc: Jens Axboe cc: Al Viro cc: Matthew Wilcox cc: David Hildenbrand cc: John Hubbard cc: Brendan Higgins cc: David Gow cc: linux-mm@kvack.org cc: linux-fsdevel@vger.kernel.org cc: linux-kselftest@vger.kernel.org cc: kunit-dev@googlegroups.com --- lib/kunit_iov_iter.c | 200 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) diff --git a/lib/kunit_iov_iter.c b/lib/kunit_iov_iter.c index 3353bca9c40f..78f566ebd4a6 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -309,6 +309,202 @@ static u8 __user *__init iov_kunit_create_user_buf(struct kunit *test, return buffer; } +/* + * Test copying to an ITER_UBUF-type iterator. + */ +static void __init iov_kunit_copy_to_ubuf(struct kunit *test) +{ + const struct iov_kunit_range *pr; + struct iov_iter iter; + struct page **spages; + u8 __user *buffer; + u8 *scratch; + ssize_t uncleared; + size_t bufsize, npages, size, copied; + int i; + + bufsize = 0x100000; + npages = bufsize / PAGE_SIZE; + + scratch = iov_kunit_create_buffer(test, &spages, npages); + for (i = 0; i < bufsize; i++) + scratch[i] = pattern(i); + + buffer = iov_kunit_create_user_buf(test, npages, NULL); + uncleared = clear_user(buffer, bufsize); + KUNIT_EXPECT_EQ(test, uncleared, 0); + if (uncleared) + return; + + i = 0; + for (pr = kvec_test_ranges; pr->page >= 0; pr++) { + size = pr->to - pr->from; + KUNIT_ASSERT_LE(test, pr->to, bufsize); + + iov_iter_ubuf(&iter, ITER_DEST, buffer + pr->from, size); + copied = copy_to_iter(scratch + i, size, &iter); + + KUNIT_EXPECT_EQ(test, copied, size); + KUNIT_EXPECT_EQ(test, iter.count, 0); + KUNIT_EXPECT_EQ(test, iter.iov_offset, size); + if (test->status == KUNIT_FAILURE) + break; + i += size; + } + + iov_kunit_build_to_reference_pattern(test, scratch, bufsize, kvec_test_ranges); + iov_kunit_check_user_pattern(test, buffer, scratch, bufsize); + KUNIT_SUCCEED(); +} + +/* + * Test copying from an ITER_UBUF-type iterator. + */ +static void __init iov_kunit_copy_from_ubuf(struct kunit *test) +{ + const struct iov_kunit_range *pr; + struct iov_iter iter; + struct page **spages; + u8 __user *buffer; + u8 *scratch, *reference; + size_t bufsize, npages, size, copied; + int i; + + bufsize = 0x100000; + npages = bufsize / PAGE_SIZE; + + buffer = iov_kunit_create_user_buf(test, npages, NULL); + iov_kunit_fill_user_buf(test, buffer, bufsize); + + scratch = iov_kunit_create_buffer(test, &spages, npages); + memset(scratch, 0, bufsize); + + reference = iov_kunit_create_buffer(test, &spages, npages); + + i = 0; + for (pr = kvec_test_ranges; pr->page >= 0; pr++) { + size = pr->to - pr->from; + KUNIT_ASSERT_LE(test, pr->to, bufsize); + + iov_iter_ubuf(&iter, ITER_SOURCE, buffer + pr->from, size); + copied = copy_from_iter(scratch + i, size, &iter); + + KUNIT_EXPECT_EQ(test, copied, size); + KUNIT_EXPECT_EQ(test, iter.count, 0); + KUNIT_EXPECT_EQ(test, iter.iov_offset, size); + if (test->status == KUNIT_FAILURE) + break; + i += size; + } + + iov_kunit_build_from_reference_pattern(test, reference, bufsize, kvec_test_ranges); + iov_kunit_check_pattern(test, scratch, reference, bufsize); + KUNIT_SUCCEED(); +} + +static void __init iov_kunit_load_iovec(struct kunit *test, + struct iov_iter *iter, int dir, + struct iovec *iov, unsigned int iovmax, + u8 __user *buffer, size_t bufsize, + const struct iov_kunit_range *pr) +{ + size_t size = 0; + int i; + + for (i = 0; i < iovmax; i++, pr++) { + if (pr->page < 0) + break; + KUNIT_ASSERT_GE(test, pr->to, pr->from); + KUNIT_ASSERT_LE(test, pr->to, bufsize); + iov[i].iov_base = buffer + pr->from; + iov[i].iov_len = pr->to - pr->from; + size += pr->to - pr->from; + } + KUNIT_ASSERT_LE(test, size, bufsize); + + iov_iter_init(iter, dir, iov, i, size); +} + +/* + * Test copying to an ITER_IOVEC-type iterator. + */ +static void __init iov_kunit_copy_to_iovec(struct kunit *test) +{ + struct iov_iter iter; + struct page **spages; + struct iovec iov[8]; + u8 __user *buffer; + u8 *scratch; + ssize_t uncleared; + size_t bufsize, npages, size, copied; + int i; + + bufsize = 0x100000; + npages = bufsize / PAGE_SIZE; + + scratch = iov_kunit_create_buffer(test, &spages, npages); + for (i = 0; i < bufsize; i++) + scratch[i] = pattern(i); + + buffer = iov_kunit_create_user_buf(test, npages, NULL); + uncleared = clear_user(buffer, bufsize); + KUNIT_EXPECT_EQ(test, uncleared, 0); + if (uncleared) + return; + + iov_kunit_load_iovec(test, &iter, ITER_DEST, iov, ARRAY_SIZE(iov), + buffer, bufsize, kvec_test_ranges); + size = iter.count; + + copied = copy_to_iter(scratch, size, &iter); + + KUNIT_EXPECT_EQ(test, copied, size); + KUNIT_EXPECT_EQ(test, iter.count, 0); + KUNIT_EXPECT_EQ(test, iter.nr_segs, 0); + + iov_kunit_build_to_reference_pattern(test, scratch, bufsize, kvec_test_ranges); + iov_kunit_check_user_pattern(test, buffer, scratch, bufsize); + KUNIT_SUCCEED(); +} + +/* + * Test copying from an ITER_IOVEC-type iterator. + */ +static void __init iov_kunit_copy_from_iovec(struct kunit *test) +{ + struct iov_iter iter; + struct page **spages; + struct iovec iov[8]; + u8 __user *buffer; + u8 *scratch, *reference; + size_t bufsize, npages, size, copied; + + bufsize = 0x100000; + npages = bufsize / PAGE_SIZE; + + buffer = iov_kunit_create_user_buf(test, npages, NULL); + iov_kunit_fill_user_buf(test, buffer, bufsize); + + scratch = iov_kunit_create_buffer(test, &spages, npages); + memset(scratch, 0, bufsize); + + reference = iov_kunit_create_buffer(test, &spages, npages); + + iov_kunit_load_iovec(test, &iter, ITER_SOURCE, iov, ARRAY_SIZE(iov), + buffer, bufsize, kvec_test_ranges); + size = iter.count; + + copied = copy_from_iter(scratch, size, &iter); + + KUNIT_EXPECT_EQ(test, copied, size); + KUNIT_EXPECT_EQ(test, iter.count, 0); + KUNIT_EXPECT_EQ(test, iter.nr_segs, 0); + + iov_kunit_build_from_reference_pattern(test, reference, bufsize, kvec_test_ranges); + iov_kunit_check_pattern(test, reference, scratch, bufsize); + KUNIT_SUCCEED(); +} + static void __init iov_kunit_load_kvec(struct kunit *test, struct iov_iter *iter, int dir, struct kvec *kvec, unsigned int kvmax, @@ -884,6 +1080,10 @@ static void __init iov_kunit_extract_pages_xarray(struct kunit *test) } static struct kunit_case __refdata iov_kunit_cases[] = { + KUNIT_CASE(iov_kunit_copy_to_ubuf), + KUNIT_CASE(iov_kunit_copy_from_ubuf), + KUNIT_CASE(iov_kunit_copy_to_iovec), + KUNIT_CASE(iov_kunit_copy_from_iovec), KUNIT_CASE(iov_kunit_copy_to_kvec), KUNIT_CASE(iov_kunit_copy_from_kvec), KUNIT_CASE(iov_kunit_copy_to_bvec), From patchwork Thu Sep 14 22:15:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13386117 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 5E9A2EEAA7B for ; Thu, 14 Sep 2023 22:16:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E70C16B0302; Thu, 14 Sep 2023 18:15:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E24056B0303; Thu, 14 Sep 2023 18:15:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C99386B0304; Thu, 14 Sep 2023 18:15:59 -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 B4EA26B0302 for ; Thu, 14 Sep 2023 18:15:59 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8BC6D80457 for ; Thu, 14 Sep 2023 22:15:59 +0000 (UTC) X-FDA: 81236611638.09.8B0EA81 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf03.hostedemail.com (Postfix) with ESMTP id D2D1E20020 for ; Thu, 14 Sep 2023 22:15:57 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MViHRLLx; spf=pass (imf03.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694729757; 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=qqxTwY9HqQXE+DORhqdyNAmY3fFbiduJ/gi0Qzq6Lps=; b=zWp5T6FbwFIsjO3/JPzQxxz2eIDe7okYnDBsrESO+wcUeqzT2uup3KJYBXvzjSoTHhuGq7 fgL822Gedcy5nm605TIZDDCKIm2jymxRv0eTO/1sCWTWeCpoSAOWTowuNiQwaug2mFiSjG l2YAj0Au7O23RudykUbXOuBCK5gkSOI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694729757; a=rsa-sha256; cv=none; b=cP03ZUTyNobUhLW1XctUOOjIj4d8JFaKfacDmqqL5E4M1GEx6+Q9VHUVlYrrfUXRZFbWbZ hGJiTRn9/zjOJrm7RkSSheKvMH2UZ4teUVVSsczWGDXtSNQkCUMNY1fL6IvdR9UXjwVa6V tsg/qqKRikv+VWP2fz7Uy0c7NFYngsA= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MViHRLLx; spf=pass (imf03.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694729757; 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=qqxTwY9HqQXE+DORhqdyNAmY3fFbiduJ/gi0Qzq6Lps=; b=MViHRLLxoNJxcstaHLsGHewyf+Uwp4/tIVxsyPhNNIEQNtScEfU39JIneJaN42FflHz6JZ dUuP7awixA2MePTNymT0hlyYwzqg+BueiC2UPJjZ4NnFiSsHNZvWbsG6flROi7PQBO3Q6V w4JbyYJIawmowCKC9V1PSNXCUuxFgz8= 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-47-NrFIS32FOnS-jSfNadb49g-1; Thu, 14 Sep 2023 18:15:52 -0400 X-MC-Unique: NrFIS32FOnS-jSfNadb49g-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 C7CF8800045; Thu, 14 Sep 2023 22:15:51 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D3EC40C6EA8; Thu, 14 Sep 2023 22:15:49 +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, Andrew Morton , Christian Brauner , David Hildenbrand , John Hubbard Subject: [RFC PATCH 7/9] iov_iter: Add extract kunit tests for ITER_UBUF and ITER_IOVEC Date: Thu, 14 Sep 2023 23:15:24 +0100 Message-ID: <20230914221526.3153402-8-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.2 X-Stat-Signature: ngi4p5brceb9ofhs5588o5xut9am87iy X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: D2D1E20020 X-Rspam-User: X-HE-Tag: 1694729757-59993 X-HE-Meta: U2FsdGVkX1/1QLTcI46L4wGspRh0XPfvnvwpHvtnhin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TTLASd2IK6NKYrb4PrwMkCgS3Lq4mcqkeIcmQevhPN9i7I9MB9M82kB0bCDq7xZHhWVROwcKXTfN+FvUBpy6CV3yI9Ic6YXofRfvwnGP8Wc+Tctp8UBNOcY3brBuM4oQS9qm5RmmV6/K9/SO7hI6mbh4Rd5UZpEOMR42FJ8dY9sZsyQNBg7T2op/TL01UvMdKJIPLmjTixiMI0fZA3zJXHTJV4j+Y29tmJlF0WtKSq67rEbx28460TZJvVBtCyZh1fEtGYe1SUHgj1lTmfI84nN0Fo4FGbNR1zK1UwgafnMq9WXo3BMzKWv8VvgYhlVdT8ghUd6m7YSsL74M9Bf8KiX+uRh0zigrrsRROHTWEDMczCuQyH/m5aCKFIIQEU3bl+sTz6n6mUhm/h//Wc0GjmcxM95pUHYZezpVXFvywnKbDeZ3Xar3di1rk+Y5CkBqDoi5a8tzHiVh1jkPbY2+AQAiBIOEZOXwaOq194T9m+vGs9VwKQoF/0g== 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 extraction kunit tests for ITER_UBUF- and ITER_IOVEC-type iterators. This attaches a userspace VM with a mapped file in it temporarily to the test thread. [!] Note that this requires the kernel thread running the test to obtain and deploy an mm_struct so that a user-side buffer can be created with mmap - basically it has to emulated part of execve(). Doing so requires access to additional core symbols: mm_alloc(), vm_area_alloc(), insert_vm_struct() and arch_pick_mmap_layout(). See the iov_kunit_create_user_buf() function added in the patch. Signed-off-by: David Howells cc: Andrew Morton cc: Christoph Hellwig cc: Christian Brauner cc: Jens Axboe cc: Al Viro cc: Matthew Wilcox cc: David Hildenbrand cc: John Hubbard cc: Brendan Higgins cc: David Gow cc: linux-mm@kvack.org cc: linux-fsdevel@vger.kernel.org cc: linux-kselftest@vger.kernel.org cc: kunit-dev@googlegroups.com --- lib/kunit_iov_iter.c | 164 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) diff --git a/lib/kunit_iov_iter.c b/lib/kunit_iov_iter.c index 78f566ebd4a6..0b7961bbab62 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -842,6 +842,168 @@ static void __init iov_kunit_copy_from_xarray(struct kunit *test) KUNIT_SUCCEED(); } +/* + * Test the extraction of ITER_UBUF-type iterators. + */ +static void __init iov_kunit_extract_pages_ubuf(struct kunit *test) +{ + const struct iov_kunit_range *pr; + struct iov_iter iter; + struct page **bpages, *pagelist[8], **pages = pagelist; + ssize_t len; + size_t bufsize, size = 0, npages; + int i, from; + u8 __user *buffer; + + bufsize = 0x100000; + npages = bufsize / PAGE_SIZE; + + buffer = iov_kunit_create_user_buf(test, npages, &bpages); + + for (pr = kvec_test_ranges; pr->page >= 0; pr++) { + from = pr->from; + size = pr->to - from; + KUNIT_ASSERT_LE(test, pr->to, bufsize); + + iov_iter_ubuf(&iter, ITER_SOURCE, buffer + pr->from, size); + + do { + size_t offset0 = LONG_MAX; + + for (i = 0; i < ARRAY_SIZE(pagelist); i++) + pagelist[i] = (void *)POISON_POINTER_DELTA + 0x5a; + + len = iov_iter_extract_pages(&iter, &pages, 100 * 1024, + ARRAY_SIZE(pagelist), 0, &offset0); + KUNIT_EXPECT_GE(test, len, 0); + if (len < 0) + break; + KUNIT_EXPECT_LE(test, len, size); + KUNIT_EXPECT_EQ(test, iter.count, size - len); + if (len == 0) + break; + size -= len; + KUNIT_EXPECT_GE(test, (ssize_t)offset0, 0); + KUNIT_EXPECT_LT(test, offset0, PAGE_SIZE); + + /* We're only checking the page pointers */ + unpin_user_pages(pages, (offset0 + len) / PAGE_SIZE); + + for (i = 0; i < ARRAY_SIZE(pagelist); i++) { + struct page *p; + ssize_t part = min_t(ssize_t, len, PAGE_SIZE - offset0); + int ix; + + KUNIT_ASSERT_GE(test, part, 0); + ix = from / PAGE_SIZE; + KUNIT_ASSERT_LT(test, ix, npages); + p = bpages[ix]; + KUNIT_EXPECT_PTR_EQ(test, pagelist[i], p); + KUNIT_EXPECT_EQ(test, offset0, from % PAGE_SIZE); + from += part; + len -= part; + KUNIT_ASSERT_GE(test, len, 0); + if (len == 0) + break; + offset0 = 0; + } + + if (test->status == KUNIT_FAILURE) + goto stop; + } while (iov_iter_count(&iter) > 0); + + KUNIT_EXPECT_EQ(test, size, 0); + KUNIT_EXPECT_EQ(test, iter.count, 0); + KUNIT_EXPECT_EQ(test, iter.iov_offset, pr->to - pr->from); + } + +stop: + KUNIT_SUCCEED(); +} + +/* + * Test the extraction of ITER_IOVEC-type iterators. + */ +static void __init iov_kunit_extract_pages_iovec(struct kunit *test) +{ + const struct iov_kunit_range *pr; + struct iov_iter iter; + struct iovec iov[8]; + struct page **bpages, *pagelist[8], **pages = pagelist; + ssize_t len; + size_t bufsize, size = 0, npages; + int i, from; + u8 __user *buffer; + + bufsize = 0x100000; + npages = bufsize / PAGE_SIZE; + + buffer = iov_kunit_create_user_buf(test, npages, &bpages); + + iov_kunit_load_iovec(test, &iter, ITER_SOURCE, iov, ARRAY_SIZE(iov), + buffer, bufsize, kvec_test_ranges); + size = iter.count; + + pr = kvec_test_ranges; + from = pr->from; + do { + size_t offset0 = LONG_MAX; + + for (i = 0; i < ARRAY_SIZE(pagelist); i++) + pagelist[i] = (void *)POISON_POINTER_DELTA + 0x5a; + + len = iov_iter_extract_pages(&iter, &pages, 100 * 1024, + ARRAY_SIZE(pagelist), 0, &offset0); + KUNIT_EXPECT_GE(test, len, 0); + if (len < 0) + break; + KUNIT_EXPECT_LE(test, len, size); + KUNIT_EXPECT_EQ(test, iter.count, size - len); + if (len == 0) + break; + size -= len; + KUNIT_EXPECT_GE(test, (ssize_t)offset0, 0); + KUNIT_EXPECT_LT(test, offset0, PAGE_SIZE); + + /* We're only checking the page pointers */ + unpin_user_pages(pages, (offset0 + len) / PAGE_SIZE); + + for (i = 0; i < ARRAY_SIZE(pagelist); i++) { + struct page *p; + ssize_t part = min_t(ssize_t, len, PAGE_SIZE - offset0); + int ix; + + KUNIT_ASSERT_GE(test, part, 0); + while (from == pr->to) { + pr++; + from = pr->from; + if (pr->page < 0) + goto stop; + } + + ix = from / PAGE_SIZE; + KUNIT_ASSERT_LT(test, ix, npages); + p = bpages[ix]; + KUNIT_EXPECT_PTR_EQ(test, pagelist[i], p); + KUNIT_EXPECT_EQ(test, offset0, from % PAGE_SIZE); + from += part; + len -= part; + KUNIT_ASSERT_GE(test, len, 0); + if (len == 0) + break; + offset0 = 0; + } + + if (test->status == KUNIT_FAILURE) + break; + } while (iov_iter_count(&iter) > 0); + +stop: + KUNIT_EXPECT_EQ(test, size, 0); + KUNIT_EXPECT_EQ(test, iter.count, 0); + KUNIT_SUCCEED(); +} + /* * Test the extraction of ITER_KVEC-type iterators. */ @@ -1090,6 +1252,8 @@ static struct kunit_case __refdata iov_kunit_cases[] = { KUNIT_CASE(iov_kunit_copy_from_bvec), KUNIT_CASE(iov_kunit_copy_to_xarray), KUNIT_CASE(iov_kunit_copy_from_xarray), + KUNIT_CASE(iov_kunit_extract_pages_ubuf), + KUNIT_CASE(iov_kunit_extract_pages_iovec), KUNIT_CASE(iov_kunit_extract_pages_kvec), KUNIT_CASE(iov_kunit_extract_pages_bvec), KUNIT_CASE(iov_kunit_extract_pages_xarray), From patchwork Thu Sep 14 22:15:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13386118 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 07DB5EEAA7A for ; Thu, 14 Sep 2023 22:16:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 916886B0304; Thu, 14 Sep 2023 18:16:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C6EC6B0305; Thu, 14 Sep 2023 18:16:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 71A386B0306; Thu, 14 Sep 2023 18:16:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5F1086B0304 for ; Thu, 14 Sep 2023 18:16:03 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 3214CA014F for ; Thu, 14 Sep 2023 22:16:03 +0000 (UTC) X-FDA: 81236611806.28.B38A952 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 7BA4540020 for ; Thu, 14 Sep 2023 22:16:01 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AkJNTrZZ; spf=pass (imf27.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694729761; 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=13E9rSgNeaf9HLX+Bou+ex5VndTo0fyGvRBBzgyH0qo=; b=alXFFLJXTxW7YB8m85+w2QFhpeJvH5KmscTqjOtnrV3+J8rFNL7J8W2r3aZ3IBiOMwQgsX m4aTXXqV73CdyyK3UcRyDtT2Me/kZpDDNWjausCBNrSRrwHQPia1TNWQDWRiqskZxj4cTc 6isSW++Bh/t4HKMh5uvxUhcIucLj60Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694729761; a=rsa-sha256; cv=none; b=oS19Jskkin9lYJKtQuZiBUYvKw2d1Z3Z936KYtai+wCt3JDj6ImHFiwShrXhu4QjI+oW5T YNPO3R+qsIjNI5YBxVQzbMhABr1uCtPY2sS3G/qJK48nKSsE/v9eLVr6t4lhxc+Nq0rTyw il7SMC7549rIi995BdHD7K15LTxJlz0= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AkJNTrZZ; spf=pass (imf27.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694729760; 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=13E9rSgNeaf9HLX+Bou+ex5VndTo0fyGvRBBzgyH0qo=; b=AkJNTrZZlpRgEmZlhvFmxCxQZ2DrRybchoWtNFUpBP7dhE8PajO8guLubPbtiZuAcprvhn iYnjgZM6FECozFLLuTByabuPF8jC1gd3s3bEXccPu4hEanfLnTSwSQSadTwZXAClTknqBm ldSmWwzS8ltvRzOWBGW6RrCbv4SCRC0= 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-193-0X13EdfBPZWIibMdnXSzew-1; Thu, 14 Sep 2023 18:15:57 -0400 X-MC-Unique: 0X13EdfBPZWIibMdnXSzew-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 C7A5A816523; Thu, 14 Sep 2023 22:15:54 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8637321B20B1; Thu, 14 Sep 2023 22:15:52 +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 8/9] iov_iter: Add benchmarking kunit tests Date: Thu, 14 Sep 2023 23:15:25 +0100 Message-ID: <20230914221526.3153402-9-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.6 X-Rspamd-Queue-Id: 7BA4540020 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: exg8z3r9r4j8biwkchcf7xcd6yy1fbpw X-HE-Tag: 1694729761-738976 X-HE-Meta: U2FsdGVkX19iIWzVsHo2cXAPzFBlnhEEa2kLriGloeoW4YWPO0AMjFaNSnEMJx1n5UD10M39Ul+mk+r5yltGP9HnqAIilz1fD1GvnfJaKMIJ7jWIDQ1SH+7+GjWBFXqO9Q9NPqaVuHfERKm1rc/POMC/bfXLTe9Zt/fHDWn4NWSWz+idd+16V5mlk1Ypqmh+UmwT/s7ilqZix3f+ISIXJ+ZbHf1eheGW8YDG7n0NHBGZSExlXMOv/zRNI1T5a/Hoe5vF+GBfybG1ng4Fds5kZ8SWZIzWq+c7kiubRHFuCcY2sSHCB0ke1K6tT/FCadPHK3UYdkAI1qLan+PD9WhPmLsjgj07AkV4X40s6a+ij0wu6xfLkXtUjOHN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6gMiprpKrriO1EtJIbNXqzmFd8ZUigdDUDVPm+fztGt 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 kunit tests to benchmark 256MiB copies to a KVEC iterator, a BVEC iterator, an XARRAY iterator and to a loop that allocates 256-page BVECs and fills them in (similar to a maximal bio struct being set up). 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-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- lib/kunit_iov_iter.c | 251 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 251 insertions(+) diff --git a/lib/kunit_iov_iter.c b/lib/kunit_iov_iter.c index 0b7961bbab62..f8d0cd6a2923 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -1241,6 +1241,253 @@ static void __init iov_kunit_extract_pages_xarray(struct kunit *test) KUNIT_SUCCEED(); } +static void iov_kunit_free_page(void *data) +{ + __free_page(data); +} + +#define IOV_KUNIT_NR_SAMPLES 16 +static void __init iov_kunit_benchmark_print_stats(struct kunit *test, + unsigned int *samples) +{ + unsigned long long sumsq = 0; + unsigned long total = 0, mean, stddev; + unsigned int n = IOV_KUNIT_NR_SAMPLES; + int i; + + //for (i = 0; i < n; i++) + // kunit_info(test, "run %x: %u uS\n", i, samples[i]); + + /* Ignore the 0th sample as that may include extra overhead such as + * setting up PTEs. + */ + samples++; + n--; + for (i = 0; i < n; i++) + total += samples[i]; + mean = total / n; + + for (i = 0; i < n; i++) { + long s = samples[i] - mean; + + sumsq += s * s; + } + stddev = int_sqrt64(sumsq); + + kunit_info(test, "avg %lu uS, stddev %lu uS\n", mean, stddev); +} + +/* + * Create a source buffer for benchmarking. + */ +static void *__init iov_kunit_create_source(struct kunit *test, size_t npages) +{ + struct page *page, **pages; + void *scratch; + size_t i; + + /* Allocate a page and tile it repeatedly in the buffer. */ + page = alloc_page(GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, page); + kunit_add_action_or_reset(test, iov_kunit_free_page, page); + + pages = kunit_kmalloc_array(test, npages, sizeof(pages[0]), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, pages); + for (i = 0; i < npages; i++) { + pages[i] = page; + get_page(page); + } + + scratch = vmap(pages, npages, VM_MAP | VM_MAP_PUT_PAGES, PAGE_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, scratch); + kunit_add_action_or_reset(test, iov_kunit_unmap, scratch); + return scratch; +} + +/* + * Time copying 256MiB through an ITER_KVEC. + */ +static void __init iov_kunit_benchmark_kvec(struct kunit *test) +{ + struct iov_iter iter; + struct kvec kvec[8]; + unsigned int samples[IOV_KUNIT_NR_SAMPLES]; + ktime_t a, b; + ssize_t copied; + size_t size = 256 * 1024 * 1024, npages = size / PAGE_SIZE, part; + void *scratch, *buffer; + int i; + + /* Allocate a huge buffer and populate it with pages. */ + buffer = iov_kunit_create_source(test, npages); + + /* Create a single large buffer to copy to/from. */ + scratch = iov_kunit_create_source(test, npages); + + /* Split the target over a number of kvecs */ + copied = 0; + for (i = 0; i < ARRAY_SIZE(kvec); i++) { + part = size / ARRAY_SIZE(kvec); + kvec[i].iov_base = buffer + copied; + kvec[i].iov_len = part; + copied += part; + } + kvec[i - 1].iov_len += size - part; + + /* Perform and time a bunch of copies. */ + kunit_info(test, "Benchmarking copy_to_iter() over KVEC:\n"); + for (i = 0; i < IOV_KUNIT_NR_SAMPLES; i++) { + iov_iter_kvec(&iter, ITER_DEST, kvec, ARRAY_SIZE(kvec), size); + + a = ktime_get_real(); + copied = copy_to_iter(scratch, size, &iter); + b = ktime_get_real(); + KUNIT_EXPECT_EQ(test, copied, size); + samples[i] = ktime_to_us(ktime_sub(b, a)); + } + + iov_kunit_benchmark_print_stats(test, samples); + KUNIT_SUCCEED(); +} + +/* + * Time copying 256MiB through an ITER_BVEC. + */ +static void __init iov_kunit_benchmark_bvec(struct kunit *test) +{ + struct iov_iter iter; + struct bio_vec *bvec; + struct page *page; + unsigned int samples[IOV_KUNIT_NR_SAMPLES]; + ktime_t a, b; + ssize_t copied; + size_t size = 256 * 1024 * 1024, npages = size / PAGE_SIZE; + void *scratch; + int i; + + /* Allocate a page and tile it repeatedly in the buffer. */ + page = alloc_page(GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, page); + kunit_add_action_or_reset(test, iov_kunit_free_page, page); + + bvec = kunit_kmalloc_array(test, npages, sizeof(bvec[0]), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, bvec); + for (i = 0; i < npages; i++) + bvec_set_page(&bvec[i], page, PAGE_SIZE, 0); + + /* Create a single large buffer to copy to/from. */ + scratch = iov_kunit_create_source(test, npages); + + /* Perform and time a bunch of copies. */ + kunit_info(test, "Benchmarking copy_to_iter() over BVEC:\n"); + for (i = 0; i < IOV_KUNIT_NR_SAMPLES; i++) { + iov_iter_bvec(&iter, ITER_DEST, bvec, npages, size); + a = ktime_get_real(); + copied = copy_to_iter(scratch, size, &iter); + b = ktime_get_real(); + KUNIT_EXPECT_EQ(test, copied, size); + samples[i] = ktime_to_us(ktime_sub(b, a)); + } + + iov_kunit_benchmark_print_stats(test, samples); + KUNIT_SUCCEED(); +} + +/* + * Time copying 256MiB through an ITER_BVEC in 256 page chunks. + */ +static void __init iov_kunit_benchmark_bvec_split(struct kunit *test) +{ + struct iov_iter iter; + struct bio_vec *bvec; + struct page *page; + unsigned int samples[IOV_KUNIT_NR_SAMPLES]; + ktime_t a, b; + ssize_t copied; + size_t size, npages = 64; + void *scratch; + int i, j; + + /* Allocate a page and tile it repeatedly in the buffer. */ + page = alloc_page(GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, page); + kunit_add_action_or_reset(test, iov_kunit_free_page, page); + + /* Create a single large buffer to copy to/from. */ + scratch = iov_kunit_create_source(test, npages); + + /* Perform and time a bunch of copies. */ + kunit_info(test, "Benchmarking copy_to_iter() over BVEC:\n"); + for (i = 0; i < IOV_KUNIT_NR_SAMPLES; i++) { + size = 256 * 1024 * 1024; + a = ktime_get_real(); + do { + size_t part = min(size, npages * PAGE_SIZE); + + bvec = kunit_kmalloc_array(test, npages, sizeof(bvec[0]), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, bvec); + for (j = 0; j < npages; j++) + bvec_set_page(&bvec[j], page, PAGE_SIZE, 0); + + iov_iter_bvec(&iter, ITER_DEST, bvec, npages, part); + copied = copy_to_iter(scratch, part, &iter); + KUNIT_EXPECT_EQ(test, copied, part); + size -= part; + } while (size > 0); + b = ktime_get_real(); + samples[i] = ktime_to_us(ktime_sub(b, a)); + } + + iov_kunit_benchmark_print_stats(test, samples); + KUNIT_SUCCEED(); +} + +/* + * Time copying 256MiB through an ITER_XARRAY. + */ +static void __init iov_kunit_benchmark_xarray(struct kunit *test) +{ + struct iov_iter iter; + struct xarray *xarray; + struct page *page; + unsigned int samples[IOV_KUNIT_NR_SAMPLES]; + ktime_t a, b; + ssize_t copied; + size_t size = 256 * 1024 * 1024, npages = size / PAGE_SIZE; + void *scratch; + int i; + + /* Allocate a page and tile it repeatedly in the buffer. */ + page = alloc_page(GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, page); + kunit_add_action_or_reset(test, iov_kunit_free_page, page); + + xarray = iov_kunit_create_xarray(test); + + for (i = 0; i < npages; i++) { + void *x = xa_store(xarray, i, page, GFP_KERNEL); + + KUNIT_ASSERT_FALSE(test, xa_is_err(x)); + } + + /* Create a single large buffer to copy to/from. */ + scratch = iov_kunit_create_source(test, npages); + + /* Perform and time a bunch of copies. */ + kunit_info(test, "Benchmarking copy_to_iter() over XARRAY:\n"); + for (i = 0; i < IOV_KUNIT_NR_SAMPLES; i++) { + iov_iter_xarray(&iter, ITER_DEST, xarray, 0, size); + a = ktime_get_real(); + copied = copy_to_iter(scratch, size, &iter); + b = ktime_get_real(); + KUNIT_EXPECT_EQ(test, copied, size); + samples[i] = ktime_to_us(ktime_sub(b, a)); + } + + iov_kunit_benchmark_print_stats(test, samples); + KUNIT_SUCCEED(); +} + static struct kunit_case __refdata iov_kunit_cases[] = { KUNIT_CASE(iov_kunit_copy_to_ubuf), KUNIT_CASE(iov_kunit_copy_from_ubuf), @@ -1257,6 +1504,10 @@ static struct kunit_case __refdata iov_kunit_cases[] = { KUNIT_CASE(iov_kunit_extract_pages_kvec), KUNIT_CASE(iov_kunit_extract_pages_bvec), KUNIT_CASE(iov_kunit_extract_pages_xarray), + KUNIT_CASE(iov_kunit_benchmark_kvec), + KUNIT_CASE(iov_kunit_benchmark_bvec), + KUNIT_CASE(iov_kunit_benchmark_bvec_split), + KUNIT_CASE(iov_kunit_benchmark_xarray), {} }; From patchwork Thu Sep 14 22:15:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13386119 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 176B8EEAA78 for ; Thu, 14 Sep 2023 22:16:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A01446B0306; Thu, 14 Sep 2023 18:16:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B0F26B0308; Thu, 14 Sep 2023 18:16:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7DC7E6B0309; Thu, 14 Sep 2023 18:16:06 -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 68C6C6B0306 for ; Thu, 14 Sep 2023 18:16:06 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4D1D5A0673 for ; Thu, 14 Sep 2023 22:16:06 +0000 (UTC) X-FDA: 81236611932.26.5DA6F94 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 974D3C001C for ; Thu, 14 Sep 2023 22:16:04 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UP6ExVRt; spf=pass (imf10.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694729764; 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=kJbp/xPUEeZPZ6xlN6+ErzCN36LIEvr4JCtOzFEoqKk=; b=OnCI2ZTxqmFLOgjYLet50A9eTNQN6gjv7FyAW/L65lM+8BK6gBC41CbDbR3IFI8Jkh1ZSj IgQ3jtANtqpva8lrDVwgic1Urim9ODX9HsZMN2whuSw6mL4C6Y1M6V2GFD3MiPaK+QKdYB kwZ4Vs1kfOIDxG0olBabYgTyrPLPdL8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694729764; a=rsa-sha256; cv=none; b=oybWWBhgp6PMkMT2NJXG4K3mWwmbU5AYDwPrDCtI8IRaOjAZzamLjeaGRDffZZGJqQjs4M DNNIVhPAKn9FdEpbzkurmd5a5KI9+GqAfXomcDHYf0hdvslk990v9LXEa+kDs4WCQvjg3d +2Xqo0pu8s7YPK9To55AjO7ux0veEVQ= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UP6ExVRt; spf=pass (imf10.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694729763; 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=kJbp/xPUEeZPZ6xlN6+ErzCN36LIEvr4JCtOzFEoqKk=; b=UP6ExVRt3EnRSBzqAe3dFicWpfExVDJ/dkY5EwVd6rgxE/9FDGHaBBl+t4r/VChS+ul2oA nteuY3OCq1imDBjSpRme8UMv7ia/Gtk+aLFH2ZNlaKL7rVaIFmXR0M/4GSwVnIl2irI9l8 a8uNBCnXQEJW6spe51dJBdrpahxN/UQ= 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-321-oafUx_6YMSSpr0ZeGoRjbg-1; Thu, 14 Sep 2023 18:15:59 -0400 X-MC-Unique: oafUx_6YMSSpr0ZeGoRjbg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 20ECC816525; Thu, 14 Sep 2023 22:15:58 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 686E72026D4B; Thu, 14 Sep 2023 22:15:55 +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, Andrew Morton , Christian Brauner , David Hildenbrand , John Hubbard Subject: [RFC PATCH 9/9] iov_iter: Add benchmarking kunit tests for UBUF/IOVEC Date: Thu, 14 Sep 2023 23:15:26 +0100 Message-ID: <20230914221526.3153402-10-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.4 X-Rspamd-Queue-Id: 974D3C001C X-Rspam-User: X-Stat-Signature: i5wfkdodutcza6krfi5ca16fz99hfayk X-Rspamd-Server: rspam03 X-HE-Tag: 1694729764-846275 X-HE-Meta: U2FsdGVkX19wXctyC5GUNan10mkSU/ngXbQY1gUZl4bzuy/jhrB5aoCi6mXLJuis5/EhotM3PdU/O0moo1Ay2u+S3J1F5wQNERTHNQZRp4LbaiM4C+B6BbWJGDPVhpkEiutiTflNxHQf88ji0RvaUSFyGP59R40ldfV78xqpt8Jk/7isC1EKzIMq3t07RnwakJPYUm+qfymBvuIuTOYcddJ6W3ppn/8uytXF8j7HDzRsDgGwVOANIvrWk0vNzQflTQj2vMvx5PvPFxvFzjOp7frQ/kVC84hxSVI0vpV5QeiOno2ytlBe1xTqVU/fHfrTuJ756jWu2chTFWWAqSE0kobHM1mT9d4IqMZAAm0ve4jQjoSgzI1sjsUFiG/f4fR8Zu889NeqiyMrFUlJ4OCrMLPE+pcWUY74d8mewGv/wwCYd6y8rPhmUaKvlJdEzu63UX1dYZ3rgq55W3SW8dM7lO1qzGWtTBrROSSyACO/mf3M2lU+KPmPuOp79QRXHYCPpeKxg/KNfQt0P1DkvH3ZTzRcLdtW+tjYszUoNTmIU59xOTjip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, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add kunit tests to benchmark 256MiB copies to a UBUF iterator and an IOVEC iterator. This attaches a userspace VM with a mapped file in it temporarily to the test thread. Signed-off-by: David Howells cc: Andrew Morton cc: Christoph Hellwig cc: Christian Brauner cc: Jens Axboe cc: Al Viro cc: Matthew Wilcox 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 | 85 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/lib/kunit_iov_iter.c b/lib/kunit_iov_iter.c index f8d0cd6a2923..cc9c64663a73 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -1304,6 +1304,89 @@ static void *__init iov_kunit_create_source(struct kunit *test, size_t npages) return scratch; } +/* + * Time copying 256MiB through an ITER_UBUF. + */ +static void __init iov_kunit_benchmark_ubuf(struct kunit *test) +{ + struct iov_iter iter; + unsigned int samples[IOV_KUNIT_NR_SAMPLES]; + ktime_t a, b; + ssize_t copied; + size_t size = 256 * 1024 * 1024, npages = size / PAGE_SIZE; + void *scratch; + int i; + u8 __user *buffer; + + /* Allocate a huge buffer and populate it with pages. */ + buffer = iov_kunit_create_user_buf(test, npages, NULL); + + /* Create a single large buffer to copy to/from. */ + scratch = iov_kunit_create_source(test, npages); + + /* Perform and time a bunch of copies. */ + kunit_info(test, "Benchmarking copy_to_iter() over UBUF:\n"); + for (i = 0; i < IOV_KUNIT_NR_SAMPLES; i++) { + iov_iter_ubuf(&iter, ITER_DEST, buffer, size); + + a = ktime_get_real(); + copied = copy_to_iter(scratch, size, &iter); + b = ktime_get_real(); + KUNIT_EXPECT_EQ(test, copied, size); + samples[i] = ktime_to_us(ktime_sub(b, a)); + } + + iov_kunit_benchmark_print_stats(test, samples); + KUNIT_SUCCEED(); +} + +/* + * Time copying 256MiB through an ITER_IOVEC. + */ +static void __init iov_kunit_benchmark_iovec(struct kunit *test) +{ + struct iov_iter iter; + struct iovec iov[8]; + unsigned int samples[IOV_KUNIT_NR_SAMPLES]; + ktime_t a, b; + ssize_t copied; + size_t size = 256 * 1024 * 1024, npages = size / PAGE_SIZE, part; + void *scratch; + int i; + u8 __user *buffer; + + /* Allocate a huge buffer and populate it with pages. */ + buffer = iov_kunit_create_user_buf(test, npages, NULL); + + /* Create a single large buffer to copy to/from. */ + scratch = iov_kunit_create_source(test, npages); + + /* Split the target over a number of iovecs */ + copied = 0; + for (i = 0; i < ARRAY_SIZE(iov); i++) { + part = size / ARRAY_SIZE(iov); + iov[i].iov_base = buffer + copied; + iov[i].iov_len = part; + copied += part; + } + iov[i - 1].iov_len += size - part; + + /* Perform and time a bunch of copies. */ + kunit_info(test, "Benchmarking copy_to_iter() over IOVEC:\n"); + for (i = 0; i < IOV_KUNIT_NR_SAMPLES; i++) { + iov_iter_init(&iter, ITER_DEST, iov, ARRAY_SIZE(iov), size); + + a = ktime_get_real(); + copied = copy_to_iter(scratch, size, &iter); + b = ktime_get_real(); + KUNIT_EXPECT_EQ(test, copied, size); + samples[i] = ktime_to_us(ktime_sub(b, a)); + } + + iov_kunit_benchmark_print_stats(test, samples); + KUNIT_SUCCEED(); +} + /* * Time copying 256MiB through an ITER_KVEC. */ @@ -1504,6 +1587,8 @@ static struct kunit_case __refdata iov_kunit_cases[] = { KUNIT_CASE(iov_kunit_extract_pages_kvec), KUNIT_CASE(iov_kunit_extract_pages_bvec), KUNIT_CASE(iov_kunit_extract_pages_xarray), + KUNIT_CASE(iov_kunit_benchmark_ubuf), + KUNIT_CASE(iov_kunit_benchmark_iovec), KUNIT_CASE(iov_kunit_benchmark_kvec), KUNIT_CASE(iov_kunit_benchmark_bvec), KUNIT_CASE(iov_kunit_benchmark_bvec_split),