From patchwork Wed Sep 20 13:03:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13392742 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 46700CE79CF for ; Wed, 20 Sep 2023 13:04:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF9556B00B7; Wed, 20 Sep 2023 09:04:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C80FC6B00EA; Wed, 20 Sep 2023 09:04:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B05C66B0102; Wed, 20 Sep 2023 09:04:42 -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 966B96B00B7 for ; Wed, 20 Sep 2023 09:04:42 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3531F1CA09E for ; Wed, 20 Sep 2023 13:04:42 +0000 (UTC) X-FDA: 81256995204.17.C5CFF3A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf25.hostedemail.com (Postfix) with ESMTP id 758DFA003C for ; Wed, 20 Sep 2023 13:04:19 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dJUDZ8Bm; spf=pass (imf25.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=1695215059; 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=VKWSpuQkETVb/v5SDgwp6hG2IhcxLE4ixy/3eQRoUO5UOtaaWvoesrcRdljTUuaja058oH Y819vtMeuawsyiQjieQDRsS3xtiT4fpL6Hs0vWJUGARHH8ZaWG59MUEg5VOhfDZOUhIE+e 8ZQhbeOXqalX6VHuhT9Eka+M5NZ9XOo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695215059; a=rsa-sha256; cv=none; b=ZHLl+/d2YheZrjR9siBaQcQiuLbLfjVeMXH1s9kS/Gs+eS6Cr0LW0EpqruyukCfKVEgZJS Ds4aG2cUGIR/beQaaU7qxMdca7dmAm+jsv1+dX6mj8vG6QagTnIJwdAxi0Fc5yAWXrofoT 2608CIvGB+YxL8J373LahY2auo7yVI0= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dJUDZ8Bm; spf=pass (imf25.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=1695215058; 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=dJUDZ8Bmqjg9ekJ26q89fEJXOIH+2HuI2q6sUpamaTfVPHXw1CujtZT88qc/r/NwpoHQTa xcmvE+Gug9EWJQYy2ikB6EQDo6oSDlngldP6ceJV/bl1ulGfcYXl42LZ+6dMWpFFKGBVEu I9gL8bxcMN840MkvWJFchMtkrInSyGY= 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-499-gqjx5typNpO8hKhRJZWB-g-1; Wed, 20 Sep 2023 09:04:15 -0400 X-MC-Unique: gqjx5typNpO8hKhRJZWB-g-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 540B189C6A3; Wed, 20 Sep 2023 13:04:14 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09F2E492B05; Wed, 20 Sep 2023 13:04:08 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , 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 v2 1/9] iov_iter: Fix some checkpatch complaints in kunit tests Date: Wed, 20 Sep 2023 14:03:52 +0100 Message-ID: <20230920130400.203330-2-dhowells@redhat.com> In-Reply-To: <20230920130400.203330-1-dhowells@redhat.com> References: <20230920130400.203330-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Stat-Signature: dm9pasjj16nbb5fsg4pw3hkptpqdux67 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 758DFA003C X-Rspam-User: X-HE-Tag: 1695215059-486621 X-HE-Meta: U2FsdGVkX19PyeC7L+TYhhNR2XjjBIe2/lXGv/oaP4zfeFm2lts/eVTOZ2Td+wuxf0Ocf+RpnkXhx10rHKAAo5ZC7Mc67yQUmAc/Vsk4KyEphLDG2EQgeUgbAc9sUFhsMoHrhRYEGlMvgiPRY3mHz40UniZbLTTIJb/JBOy9Fw271TaO2hHJTB1sE42WsRGZCBmlxo58GgG2F2ijehOufpFU+CIIjVFSFizmieKGJth2nWuxu6gwfpE5NnXFwXDjiXBT4qwpF8vIXo7RUp/5gVGchewMhxGMwxcLdR0rpsxsuEq5/M23nfEdkbBx2hz+1TScrSPRfn8Q4I4z02lAQUIE1nTBfsnd0H57TtuySZjIEXEs0Tdbc3N161y7HGkOfCv0s9rVZVjBnGN4gZrPNR9d1vHZmVuQ8x98rwtQVRWHCU+v1Vx44pVU2JOZ3EIWm0FF7GFIEfKHrUhWjMThHUktETZ+qzn1DVdvdRs6f19DwAN6acUdRwPMLlSzbWS0l+SkIsrrPkwEcHgnwtzR5A4nBgmwy9p5GzvXA5omzVABANSwj07PS/7nfT/EDhkU7U4Yj/BVDbFYNw6jEUPajFNTcpAtAecv3T3kIIbDMKgv8HOhoxRvwrIWxvSexilfpH2KNsHnDMtGq3Ab+LEfExiSQ/T7AtsnV7jQtH36EgfShIyv9pBuyVw97sTNBr7JWX9QU9atfy2MQGXzqUiNyh4bY8tbVxf/lZh2+yzW/Qpj/pC2kutWBNsYIO8VVK2a+Z159qnBxI9IiQLq6un2fAYG1gtsTRRY4DFFLiw2Q93Jme3e+4pfw3xNM51f5yroNyoNYwQEdngt6YyIcZaN/9ISs+GHyAy4QbHK+OdrL/9wi5iOfXY0coMAlJ5y9IziufcgG5nMVXmncRq5arNkyHzc/kK3JN8x18M8SuapnwMVfzSqxt6lKvaqHhslKbR5Z2T9B9xRIn7UY0fEMYA gY+8LUrO 5F1jPX3p0RdwDN6kl3wPF+9ZDzoXk6SU75MkImFqCntJqLA2R3/ZhPI3pacunya+Q2hVE0BQZK7SVeNPmASqv3W6Z+iVGW7ZP3QT+OtRWft+id4cfl6qhr9qN2Fvwl47UY61gUUvAVrGhd5I5PHzhofbKA6LT55EddnZTAu3wBLci6TmeG+A3WCMzeU9OINNAJTmjAsQBDlCVBo9q7T5A6wDI/lPfRP7hOPHMhl/9WR1+d/n3iXOx5qMEWhAXHMNfaOyVRR+hOpBWUl20ZRyJVZ0D7P7OWNwLGbU31cum3owmYb9gmirB8fY5eLe2E13iavSLYMjRhny4R+den0ejkVz5Bw4IVPkB9xc6Y3qjgfpe6WNmn9Na92X8uIe8gIJC1crTolGrVv5Xo7YrrMGcX3t21uGUYmEea0XfdZIc5+Do0ruxyW1zwaUA9bxURYtdtDC4+JfMUtYAlaok6WMMLkOB6sPLIeFZ356rWiah9p+Lh+n5GAYb3aAMSjh7kRnjrHKakSZ8jM47zCduRMPTlZDX1jZWwdkzTtpdS8ZxawKmowtF3KJcI+NC3g== 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 Wed Sep 20 13:03:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13392743 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 2743ACE79CE for ; Wed, 20 Sep 2023 13:05:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B4C7C6B0158; Wed, 20 Sep 2023 09:05:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD44A6B0159; Wed, 20 Sep 2023 09:05:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94D2A6B015A; Wed, 20 Sep 2023 09:05:01 -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 7EA986B0158 for ; Wed, 20 Sep 2023 09:05:01 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2C1C14088A for ; Wed, 20 Sep 2023 13:05:01 +0000 (UTC) X-FDA: 81256996002.14.67E740C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 4EF6C400EB for ; Wed, 20 Sep 2023 13:04:33 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="ZpLNpSN/"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695215074; a=rsa-sha256; cv=none; b=nEBjaNQEDpp1f1+0KkqWqMQZ0SJU15bu8i61haF/Sr5zcC7rRPYut16rB3CkwDkzOQYIES 8qruly5HdreXUSm732y29q9DX5fq/LhvPHjsw0vWxDlPhErq6UoeVkNNzr4bvnon2gXnLa xpWjArJ5NOft2aW2ZgF1PDkkijgWcq4= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="ZpLNpSN/"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695215074; 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=T2ga/gJy9TYgbBhq5thzPtcnf94EFOvUj9ePyYddCw2p7xlH1q4oexGbb6WDxgTEGNK8cX Q6LNvmGYMiuR7quzlFcSz3jiR5qXcNH1sfN1Vlv2WMRVoeGHQLnQJmHTNQzBxaVodfEpyM hFGoPD5Br65RHdqnubs3C/u+HiskDD8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695215073; 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=ZpLNpSN/NaIVHyL0VLdLvhNRMexvds+mGhKj97RwntuYHYCTEEgKqDVsD+i8RP+M2tXOuV y4cLGUJrtlKJ4bPIn15N7cHliVqPX8Bd3x/zx8vcuT5Ivcff8TkrV25HPYq+6dOGYBHrSf WMEF8uWXvaRd2XkfAHURRssrlBNrqIY= 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-682-AR2qMwyVMnipdkVKppdkYw-1; Wed, 20 Sep 2023 09:04:30 -0400 X-MC-Unique: AR2qMwyVMnipdkVKppdkYw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 F2277101A529; Wed, 20 Sep 2023 13:04:28 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF1E3492B16; Wed, 20 Sep 2023 13:04:15 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , 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 v2 2/9] iov_iter: Consolidate some of the repeated code into helpers Date: Wed, 20 Sep 2023 14:03:53 +0100 Message-ID: <20230920130400.203330-3-dhowells@redhat.com> In-Reply-To: <20230920130400.203330-1-dhowells@redhat.com> References: <20230920130400.203330-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 4EF6C400EB X-Stat-Signature: 18pcsdxex64i95w81ipibtcm15uf97cz X-HE-Tag: 1695215073-632847 X-HE-Meta: U2FsdGVkX1/MRx9pz+NPwcwOXTzDoiTXGUsWnk9mQppiGOpf/vqmSXzW1VWdA8gwV62w2xZg4vqHGB0IMt9rEMNfo5KbLO4l5Xj3ARsGHaVtAVu6Jc4YKfWcXz8htD5P1dybU6vzQmdHP4nlVPIVGVl8wMu/O7h9sYWsg259Xk7hFN35Ta9y8yoL8DlbrsGtDOm51p976XPz2irO5b1o9tdrnJzBYB8MgcOZZDPVK/Y5m3db1A8yyomeUQw8BVJ8dUxFH7AZ/CAbDBaZhGrniemIDW2dZ1QRCAvvL0wkcKy9P1oKmhmne+AxVgDW0Lh094SOuWSlW2rSwS7zSJTCsFgM40o6i89VG9L14tzVIuu+r6FzSTW9HN2zqtUaFTmZy4K00Vdm6gY6IIxafVpVW4IkFpnLYYXe8pXnaKXe/o8zHA1wBdzELmzsQR9ma2jmG7rEkIRfGA2ZYlTm3M9/IZIHDKLsYiSOCAFgOt9kKDWYd2tpS2RY69Id3EphAcagh8U6PJI51DYDdnijE/EpxgfRws/7SOH+jA4c7ENRVCCliG3HFf3U5kFwh6ZFCCNJ619f7CgAy7l5so9qywFr1HKvLq7jOWzy9RTJcr+TobhpD+HlTyBEHZ+6TEOY77+G6oM6RcoAEeKsOuv1ckJ4ZKJffa/q78dnwoP7o7Yx495i+9AuExQrv4COQf+RS2/3TOpGd1RnJjo12dhDuJzSag9jTIl9yR8dDocUpID//kh72rUn+yQAUw7Fb8bgJz3olhWz/xIS2jOlUfI9QoIaO1w1rrZsf2+vXeP8tYfk+QQkCkVNZi+P+daZO1ZjV0xaCN4eo9Ezu75SpyEidYhA5hozcDdViN1qqj+w9ef5SiWGn++TqsqXZHBMBbiiY3MwpvWvMi8ld4U698HBh0tTmmIw0t3pj7MKYCE0ODLrgRARDAFi8nPhCGFwjRh+UdS8N9fbH60aYTXpvWk3VXL 7GUCAgq+ 3X7fvtYbO71EK4DK6snrRW08Uag9Ot2dlB6JV0AZ2FuRjpuNYBV8skLwPjtC/g/IBTgdW71LXaj4SVgwsG1uQJPAxVpYpSl02+hCrNajKNIf3Wedmajd1DFNj0eyep4/bH4T504sHS4XqP4KvEXtsJkT5k9o+gWBZ4OMUsNKx33AYVm67eoSlQUQ+gCP79noAvQiBwd89VGyQI4kMIcY1V62GrtGZqKRYsaMZHHElcSKmCo0cEwRxe+s+fcWOh8kjyfUTKrH0BLty6ElZ7UOAdrplerQ4pY/lwVylL+BhHfdb8LBB2e89N1vgM8xhXOnFanyJS19tFM9GHo1I9VI38GohjHrSUHd5fxYs4nYiNWq5wWZ53tae10nt3PkIA7f1nxPz4+HQYdYDrpboUaj7aQZGWCSOmkf3p8QQ04cNgTaQuTmQsM8YQRhiKJ9biJE93A7fy1nr++sUAZzkuPcYBxuDS04SgxMIwIIw9CaX0mqLGW4W6W/VV/OAv93T9IWObKJB 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 Wed Sep 20 13:03:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13392748 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 A3F07CE79D0 for ; Wed, 20 Sep 2023 13:05:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A661B6B0164; Wed, 20 Sep 2023 09:05:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C6BE6B0165; Wed, 20 Sep 2023 09:05:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 81B176B0166; Wed, 20 Sep 2023 09:05:24 -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 5F0F96B0164 for ; Wed, 20 Sep 2023 09:05:24 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3C192160467 for ; Wed, 20 Sep 2023 13:05:24 +0000 (UTC) X-FDA: 81256996968.18.69AFAA3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 8D8DD1000C4 for ; Wed, 20 Sep 2023 13:04:46 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=colB3xWh; spf=pass (imf05.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=1695215086; a=rsa-sha256; cv=none; b=qniKRbBT2i2YDc9rM/CF7A4U79nmNT6ShOGHJmLjmlIWEY5bw7/dXlCGF0yg9InS62M1IB 3FI6XCb6EfnDuDMpz9Rb8gWcNgXBY8umQ0aKpZwii3gswckJezRAa1gJfDFzwhy9mnqGF5 GCrw7TL5aYxrKE/htuRyzODv+ZYrkD0= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=colB3xWh; spf=pass (imf05.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=1695215086; 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=VHXz/869Oxv3sfFm65eas7S4zpH+PrUAtxL8MOr8fFuQTnB7Gwy8+dm7Q82auinyrVxuOd L8uPzcw87DWbaOF0VLR9uxGr5b7h2+5hMih+AoE4IQhDwq3KQO29M6Z0m5NghUVzGrFqL7 /KTfyReH+L5Zt5yEDq4q3dzt8ms0cow= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695215085; 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=colB3xWha74ihpi4uYBHk+oXONxV2N6O/02WTkbmtAXfnDk+aHMXtENCpfQryU/sBnuGiZ W0lnydDUs0274BeAPFEydzz7f42IyMzdM/jxvk6XeGXBNoVhhy1rBz6xcYpQ02dWclliJN rSEHkbK3dm1FqLJFTU+5S+hOPFMYlaM= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-100-Jfs8nTrRN4a0ci59La6Q3A-1; Wed, 20 Sep 2023 09:04:44 -0400 X-MC-Unique: Jfs8nTrRN4a0ci59La6Q3A-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 714F02999B33; Wed, 20 Sep 2023 13:04:43 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id A65F0492B16; Wed, 20 Sep 2023 13:04:32 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , 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 v2 3/9] iov_iter: Consolidate the test vector struct in the kunit tests Date: Wed, 20 Sep 2023 14:03:54 +0100 Message-ID: <20230920130400.203330-4-dhowells@redhat.com> In-Reply-To: <20230920130400.203330-1-dhowells@redhat.com> References: <20230920130400.203330-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 8D8DD1000C4 X-Stat-Signature: gwnzjzkhxuwmcy1djodb6qar948m5kez X-Rspam-User: X-HE-Tag: 1695215086-727850 X-HE-Meta: U2FsdGVkX19/IgCCF+iX3s7+D8blg5fwPR8Z4h6Ag8EFGHfyreNzxSXNSDdlPdVFx8Ym28wRWTAvVDkwS7uzAwpPH1u1Sy5d7F4U/7uJn/Re8hGBR/REyTl7zWXDFV9fZKj6HhaA87zK/CCUYg4LE/qrN//H1x/puK3qBSHUSCZdIF9zdrCObKFdb+A6cAJ2M3KQP0G/PZPz7ErLXj3C3E6w32S+dY1/W1dnLwm5A4aP1eBb39fURVWX892Bjxbfz/qzBz7jrQ3Xc9gvzWrrc/uUubCErrWikid1Xx4PyJXFsiYMSozjmq5ny6d+C/hjFJ5HkjuenTqEeeRL3XTbXCpbj6iEWvRjiid1wUdD0ZvG+t7c/3UZHdNh+nus4TSEFTt0wFUEksO8Sy+4lPNaUpyb5sfgNOrxzaV0SNhj64ptybhwvBDZlV3aQuXb8HFBkDNCHvQkjA4jGVLKbRFoA3ttgt+6IIlL6JyZbfI910Fsra2AqRq9/QkAxW8MQRTLT5+/Um1r69IL2Y2xYsXxYAmZnt8cCLl4AEzD8+0yyDX/zsPZ59cDgxfUGEPSydpI11hJDLmuAEhy5c728KRbFsamZx3OMavuLF8roUoQlZaZDGPv0wfy+1yxqtqHmv39BIDHoCqFlTQdOIGMDXDr+KXKdjM3Ki1jS7fuYLHEetI/wAd3kAFHle5nLFXQ+liI8hkoV0HDjAjghcz7EWWhKD1DZqH5963l1KAzp7K+AjSnLIraNvs/pT8aLYahAf8C4nP84QzW6R/f2DLKs4LcYKIhamkMGo7feB2znbG6wsvzWgy9Kjf7a81jD+zamLPpiQepGCCmeFsCRBOoud5s8uDevxIJCG/nwCCf4N4j/yb6XwKvkQwZGTUWCmmQqPJOpcUqPQDxxN5sXDQtE8JmtAdSPXQjIQ57kGQ0WZ3ZNcEzTsEwE1+kPKS4iCCa+HclK3E6yXnKJF0FGLF9vYP dYC5otqw rZ7JFrdyaSsjzGfv6zPnzMkBUNhoiaOzD5EIU08iSkofHOn2klOEpvhLmPFuerDp4xxPrir21gQk9znGbrYmVMZESUPXekA/FHBfs1ouPO80nRNE+jUm4xbrFteZMeUzuVWnsjuGhcrM5bacEo48oIGTVU8dcxkQH+nb/kHYGsHoW3r7q95J+b7kloYUB9beY2qq4sEFnu3Fk8tELG6iIqHEt0zNQSZ1dlK7tH9j3fI2p+slxT70maW7yurWfbfLjfWBOWLOFyUZqr7azsacs82tZGO+YxTIJwWycOX3kjWF+aus9ymsCfK+CXGNhsYK8XBBDg4DcZdvmG50vDx8SBnpOrFUWMQuExxla/s3q9TYIVv/byJUgRnKuzx03TZjFC++ai83AWYls+FapKlCR6sw/WUcQtqWiBRsJaOBFNKJ0pW7bWjYwnm6yMfdZrVqDpDgnCzBPrfxpPjfp7P6lU5g1h3gjqEiEgWitvtbUyXYBdrbrelufnYPgCWTs/+oArmcr 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 Wed Sep 20 13:03:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13392745 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 8232DCE79D3 for ; Wed, 20 Sep 2023 13:05:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD1556B015C; Wed, 20 Sep 2023 09:05:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C5AE66B015E; Wed, 20 Sep 2023 09:05:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD3786B015D; Wed, 20 Sep 2023 09:05:05 -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 825C36B015C for ; Wed, 20 Sep 2023 09:05:05 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 412FBA065B for ; Wed, 20 Sep 2023 13:05:05 +0000 (UTC) X-FDA: 81256996170.18.E7E44E0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf21.hostedemail.com (Postfix) with ESMTP id 28F0A1C002F for ; Wed, 20 Sep 2023 13:05:02 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NEs3FwcL; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.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=1695215103; 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=396WfUj2Rbvj11S3Cw/fAQcOaLl25HdekcT0pauWRKFLGTfSafD4jgwoUFjnaxoddUze8K Er8hiNVU+h0i1OdRHno5YcZKMCBHuibdN1SnvwPk0r5BKM6CHL18XjUDvOjG/Gk20mz5Ph 2EA9kA6VwEJuErqw6zIHDIxQCqN6BH0= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NEs3FwcL; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.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=1695215103; a=rsa-sha256; cv=none; b=M1AqgFwhNrdCkqmA2NM2Y4R7SCOhnsWNLqMoPIrmns8XFBD69hkR3DcJL7CYRkvwS+Ok68 qBjBJRCz+ZKesH+YcQNWH0+upYmxM6zgCImbe5WQdW5zFljnOBkbdwllOaaShINYUTFd/j L20KHte3baVK6LzhPv0rRXzb42FGhA8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695215102; 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=NEs3FwcLwwhC2rSwEtLV9+dNtl9VwmXsh4kVrsyjVi4frosdByjyhou4vBeTdox1ZT1HRO 2jcx76WIyLKbc6NM8XqQyH/9CJSJ44zw5qlw+9bYWiopoj1fXDG/WUuc8jP1+YTX0tYDOr x5qL77rVVwFOkRFbvoYtQT11tXVyuks= 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-231-GSu9rdLnNoOiK0fFC_BW6g-1; Wed, 20 Sep 2023 09:04:54 -0400 X-MC-Unique: GSu9rdLnNoOiK0fFC_BW6g-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 CA268101A585; Wed, 20 Sep 2023 13:04:51 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id C3ABF40C6EBF; Wed, 20 Sep 2023 13:04:44 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , 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 v2 4/9] iov_iter: Consolidate bvec pattern checking Date: Wed, 20 Sep 2023 14:03:55 +0100 Message-ID: <20230920130400.203330-5-dhowells@redhat.com> In-Reply-To: <20230920130400.203330-1-dhowells@redhat.com> References: <20230920130400.203330-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspamd-Queue-Id: 28F0A1C002F X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: oeo7e81hzdanfbkmzf5n8hej3swxkik8 X-HE-Tag: 1695215102-886250 X-HE-Meta: U2FsdGVkX1/GwUm4yICNjAuoPeA3BG/tVB3wiYZh+6t90waacdO9aQ8WDJbkrYmWDalqkMlMeXIFMZFrgOHCnwGfjr+wGwb8HqIc+mvM6CI5U9iA6B8RynJv4lNpM5V70+TOBj54jBYjh4fQgOfep6FI0LX5Jjw2jwmY2E3Q8mpWj3EpSlQp2J/4SO4oO6gxx2xiPc/GxTUAAyLwciUCpcE+ZaryO61SQ75io6jCUxKG+n2OfgNHnp2kncW09Td6HTjT57OJz0jkvLx08TlLnKvp9nXn6OS9wmw67AXafTPeaXRd9ueMD0WgePwzhzSzNg1iVJUGBcmFuX+9O9xm8HSLcqsyhE2vO5Y4umJTPL+6fXM5mvdwS0dRCPAZyxsGofRDiyxIRB4XiP4AbloSdlJjCu3t0NqVNdpn+MkPEsURfvT3avJTqXYvtzqTjfwf2EQfnT0hSgD4tKU3kvA50kegEailIDItRlThQeoSdrNGGfwrqxb0H3O6GRE8hiGNmR+Rsxkqxzv3VbEbDjDK9DQnS2hbh8ZghoE4XluuwZyFQ5YsXs2r/2LrANhefEOwf6A4PZ+s8MfVxgqCmM8jeXVrFYvht/1wrAQMxssI56m32ftc4GiyIdC5u07SOBhfTO4fWm0E3K4fY/04RN1CrY3QmwYohnceHWpwgCmACuMsq7CXk/6tNkPyUK6+WzlaCvs/pstiZpozLdCUS76dkl9s97UWITsmD3974vrUkoFPlMMSJwL3nZxj2JvNaHVTuC4AWxCCs+uAymnMUwyndgw055RhSuj8jEwwawjIqOFmw+SIpEtjsJi6sTA6LaupL3ESI6rXHp/CKTfeIorPULhaTYpIFXlr10bZG1KNCOTFMZxYZKlMLkroQCjAT/8tmvGvNh0p+WQWIeFk3qCnpFshzQB55BFEYZOsxcp6T0QhcHOCMDTEQ9MKzCYMSQBwO1oFZRXBmEoWVnT6rnZ KynukuyI c05gIacyXlrFL199aEMlt4N9G/A0OVNUF1wPsS7g46R+aLq4DPfCApetKC5ubZuB90lX0WoPltYXJqA+hFJNkA3lz0+OEsSXxj6XMaAQ42tx4/I7kYwkhrThhbRzA78rj0zq8bEgnKfbcyfUc1EmCES+eDOI2tgtyNVggoV4SIELgcSQuZfoFNtrznDXV0WCMsUxBFP8zw3bSxgFLGbQFox/lQPAyH2zY9CUuhFU5piE4LEJnkUzC8vJoEXMsb5vYK0+8MBgHoCw2DPzdF7ci13Ou607dftBcXwDi0VCpTwNiH6vWyL8G3k1yy3N7pZfXlmWEMqqQ0I/bqh2wz2AKT4clKVanSIAHh3OsWu8Du/S8Wq51yJt9LeMyzClBWyKsMKIa6X0I+JhuvO9pvGyCQXU5qdka6ckac3GCbJIUt0ew3G9NNeUcmeaTzpR4bdo2OCZFBsTQw0J5yGM5moivy9BGSBl+6l52UNcwIZDP0Ot6gByRkfuc9eVboqexWH3dRMNC 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 Wed Sep 20 13:03:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13392744 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 ECACECE79CE for ; Wed, 20 Sep 2023 13:05:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 817216B015A; Wed, 20 Sep 2023 09:05:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 79F646B015B; Wed, 20 Sep 2023 09:05:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 61ACE6B015C; Wed, 20 Sep 2023 09:05:05 -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 4A05B6B015A for ; Wed, 20 Sep 2023 09:05:05 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DC7DCB3400 for ; Wed, 20 Sep 2023 13:05:04 +0000 (UTC) X-FDA: 81256996128.30.7A2D00D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf22.hostedemail.com (Postfix) with ESMTP id EA688C0042 for ; Wed, 20 Sep 2023 13:05:02 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EY1PgM+J; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695215103; 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=uub17mzu8dgUj1tkqvUjJMJqsHG/bWf8Fylywc+muQE=; b=cZsIwOHDQmC7ZFmrQcCwP3KgjppTrR9dB9ZtpTw+FP5FTb5Ml/dNaq5P0lT6IMfh/692o7 CSk01wXd5dPyt/GOwVF+hIM82Elyum09osPQglOmrptWoIj5PhlUjR7qQa0I5Kv+pJto7n oao9WAfR2Le5+YzRs16DGzy8wGjWjNQ= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EY1PgM+J; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695215103; a=rsa-sha256; cv=none; b=itXFu7vIDhDlJ38LfuuRMwQIO2mi8t6IUfySwUZDppDtaYOagFOPaq+17+10d7HBS+9uHL MGv8Q0XodM/5ywaQJC06fn4c0F4E3TMB/9yS3jvomuAALTsRofW0ECiz4l6Gp8RbGKrgNT eW8bw5DmpwUdjt8OHtWWqeFH+nuFHtM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695215102; 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=uub17mzu8dgUj1tkqvUjJMJqsHG/bWf8Fylywc+muQE=; b=EY1PgM+JBGGWJsL1itf5wf0GRtKbPiaGlicCKoGdqDeQkwVK8co4Dag8cu3WQQMSyGoSlf mubsEOhoS8UYGRRAUHFk80Ishp1B7xx/dkefVbBDhaO482xCSWcdGnMlyc+STHACylwJir lPOUFAFqrGq/GmLvNEwWY2FPHAb8BRQ= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-106-K9l0k3J9MKGNVn_uOBNDsQ-1; Wed, 20 Sep 2023 09:05:00 -0400 X-MC-Unique: K9l0k3J9MKGNVn_uOBNDsQ-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 8B6913C18C27; Wed, 20 Sep 2023 13:04:58 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2FF68202696C; Wed, 20 Sep 2023 13:04:54 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , 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 , Huacai Chen , WANG Xuerui , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , loongarch@lists.linux.dev, linux-s390@vger.kernel.org Subject: [RFC PATCH v2 5/9] iov_iter: Create a function to prepare userspace VM for UBUF/IOVEC tests Date: Wed, 20 Sep 2023 14:03:56 +0100 Message-ID: <20230920130400.203330-6-dhowells@redhat.com> In-Reply-To: <20230920130400.203330-1-dhowells@redhat.com> References: <20230920130400.203330-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: EA688C0042 X-Stat-Signature: 3mpbxg683azhbcirrrj91ju4c8utxhmx X-HE-Tag: 1695215102-193240 X-HE-Meta: U2FsdGVkX18mZhT0g0+afiNUycVg1uxqP549YQLEIiX5Jfw+vSDtO2d7Vv6rBABPdsyQhu/eZyy6INlSoXcH8hgS0lbgYkgvG6peIgYHtCL7UGSySJf6rpo5C/TWnHooUnc0u1vxnRK45FF9DjnXlEUFW2mW0UC4KmOlDMAG0UiGzia6h/OJpJmR1cb6j1IEZSZdhqK14zrL+GND3lAlOlWJ8+w6kpg4+UAWFfRf6s8fSGGUHnNcgFAqN480CLpxIzVuB/ULGC+1ydeFGHJ742RVa+UPKiDYFoBr8b6PeVlGET24i6DAfha9dfgTQoslzr1t4Ne6QeK4f6qjr2tQLXFyrhGWldxEDvXsGubNkyLksUcf2qO6yayPtvBbaf5fGAWka1siHqZiILZZihG4l4+5Fy+q0JDKh49BbN3jrhCcUsjnDElFLcSNgwlEyDdERAFjUUG7Uk8O6fcNE7WfAZkR8Ue2RTxWRhLjQjMuP+6YdIQYftn5HSAaFDKpB+UqmtK0hAab+JXBxGhiMbLR+yefPyOhp7rACL4M6F0FGRF0oJEdY6xFd/IgC/7Hk3sBdYTvKJWBaVuUciHOR41Pp0OzwdsC7GYpK10bfJFOHEZb9gJw9XJrSXTERyvktH9Xu/6j7z6iIbCBBnNvlIzeJtz4fLqjmpDfse2mdO6vDFznuMjrUzVEUeUFEiWZh5I+cVOMf58yjgPJ0g5XefpDCFUCa/zG/hE70gKA4TMwXILciF2hgU5JUyEyNQ9uoOj2XZTj1sYejmErfn/My0sLUFUuxwsiTarXkLSEl8ajilwpDiCYNS3Df7DypYh8EwFwyGNlhteXgXg1nw2z1zzR82v11DVqwOWd+P35+pgK/x4k73B0F2jDTKN+k3eY1FLXXFo0Y8atkufu8poSxmEeYRaFOA/iC+oJHAz/Hgw0JpfVKCOJjONS1SsLhVhG6zQl66yimzj56okCzK45kgi Ed86WBVK 8vi7iDoWiPkHCLxPm317vUuVYRFxHmUbUJ0glybQXn+DyfrUUiQg+qY3R7rcTCAsnJavbrV0Hx++m0+noHVRGGo/Sy0LDFfUeLbBlJCYVV2q8Xhvk1j+FRurZsj8SAbqnr7oyKXQ6GwKt5HVuMNi7NszNBQjv0HD6k5s7MlWrSLM/qSMQEyclO0q1v7EiCCf6iVeC2A9Npol+eevh/FH6nBieDwWMELooJJBIInERC79iTr6RBGxBCi2TjkIyUqzVT81+60yPBXs2cRHQpa8UGxy4vU4wY2cSQwpBNw1HJFYloyNff8/x+3gp6OC8pC9XQWZbTKXoTN2Xdcn7WZ6oFOyywdoer1m8shJTKzdCiSHFTI2MUksKYFN5gA3/hcNlM36yCnfWFqkEaQ32UJrntMwFc83BMpY0TnKl1chC4OXJN4GZalupYgb6Lwa89DEkEsWYgb4n6uXsF6VckVJhd1j9RRjBd2yXKuCSOm6wPnDzYUSPc7751XbbtD/9MpQWOBo4hfjxqkYZFBq118N+FHEDdgsv3l4d1yM+dzjzDit1iS7asmHzS7AbzpUNqj3A8I0/bZ25kmr/2YLL3YMjoSQSy3Hcxbv+FJ5V9msNsQt5cHp+0/hzpw/+qzTrXyddbdW08h/k5ByWMQN/ny218GPlm4GZVjkLL4apEcdGVNxokkCAjSIdI5wH+XcopRexQdK3RqP4FqoSNppDE0V/bAauEg== 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: Huacai Chen cc: WANG Xuerui cc: Heiko Carstens cc: Vasily Gorbik cc: Alexander Gordeev cc: Christian Borntraeger cc: Sven Schnelle cc: linux-mm@kvack.org cc: loongarch@lists.linux.dev cc: linux-s390@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-kselftest@vger.kernel.org cc: kunit-dev@googlegroups.com --- arch/loongarch/include/asm/page.h | 1 + arch/s390/kernel/vdso.c | 1 + fs/anon_inodes.c | 1 + kernel/fork.c | 2 + lib/kunit_iov_iter.c | 142 ++++++++++++++++++++++++++++++ mm/mmap.c | 1 + mm/util.c | 3 + 7 files changed, 151 insertions(+) diff --git a/arch/loongarch/include/asm/page.h b/arch/loongarch/include/asm/page.h index 63f137ce82a4..c7c5f5b4c0d3 100644 --- a/arch/loongarch/include/asm/page.h +++ b/arch/loongarch/include/asm/page.h @@ -32,6 +32,7 @@ #include #include +#include /* * It's normally defined only for FLATMEM config but it's diff --git a/arch/s390/kernel/vdso.c b/arch/s390/kernel/vdso.c index bbaefd84f15e..6849eac59129 100644 --- a/arch/s390/kernel/vdso.c +++ b/arch/s390/kernel/vdso.c @@ -223,6 +223,7 @@ unsigned long vdso_size(void) size += vdso64_end - vdso64_start; return PAGE_ALIGN(size); } +EXPORT_SYMBOL_GPL(vdso_size); int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) { 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..85387a25484e 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. */ @@ -151,6 +171,128 @@ static void iov_kunit_check_pattern(struct kunit *test, const u8 *buffer, } } +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; +} + +/* + * Attach a userspace buffer to a kernel thread by adding an mm_struct to it + * and mmapping the buffer. If the caller requires a list of pages for + * checking, then an anon_inode file is created, populated with pages and + * mmapped otherwise an anonymous mapping is used. + */ +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; + + /* + * If we want the pages, attach the pages to a file to prevent swap + * interfering, otherwise use an anonymous mapping. + */ + if (ppages) { + 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); + } else { + kthread_use_mm(mm); + buffer = (u8 __user *)vm_mmap(NULL, 0, PAGE_SIZE * npages, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, 0); + } + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, (void __force *)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..09895358f067 100644 --- a/mm/util.c +++ b/mm/util.c @@ -455,6 +455,9 @@ void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) mm->get_unmapped_area = arch_get_unmapped_area; } #endif +#ifdef CONFIG_MMU +EXPORT_SYMBOL_GPL(arch_pick_mmap_layout); +#endif /** * __account_locked_vm - account locked pages to an mm's locked_vm From patchwork Wed Sep 20 13:03:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13392750 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 81EFFCE79D2 for ; Wed, 20 Sep 2023 13:05:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D5E66B0169; Wed, 20 Sep 2023 09:05:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1862C6B016A; Wed, 20 Sep 2023 09:05:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F41776B016B; Wed, 20 Sep 2023 09:05:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E2F4C6B0169 for ; Wed, 20 Sep 2023 09:05:49 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A160DB39A4 for ; Wed, 20 Sep 2023 13:05:49 +0000 (UTC) X-FDA: 81256998018.26.CE3F6D2 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 CEA1DC0060 for ; Wed, 20 Sep 2023 13:05:14 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eHGTIxTV; 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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695215114; a=rsa-sha256; cv=none; b=RY9OLTmdEhNaHT2HT61WCJvw+i9ovVomh3T91F9NiLqUO1kTRnqTkS8kN9ZqJhh3OUANId XRRhC+dDiMIDGBfZ3OiIclJgiEyPcc23/fTgz8YMfM4Hw1saCJzJaukzppK5mbw7bsdSTa LdjY3qGDoMWry5aR8GG78M7IY1CuO4U= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eHGTIxTV; 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=1695215114; 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=JsA8rUgjW6/Y4e1LExitHFafQGFdmwIk63HoELAb6c4=; b=yCX+/HoE8XHoM0pbkCez40HFXJivB/8jWKHMZZ4ZLFdh8635QND3i0FDjum7i7DaHr+j6w f8lizfAG0q2VJKcn+8g9pCramQkJq/Js23jc+OQG/JKR2lk9NFOTd2ahVJkz2g08RFrKvd y797UyFHHlrnr1CqwQdEtf/fzf9fm44= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695215113; 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=JsA8rUgjW6/Y4e1LExitHFafQGFdmwIk63HoELAb6c4=; b=eHGTIxTVWU1ysgCkfgiLnSfDNaCKHRTF9i9zRdVXUVmsaVBmiITmsTD4StyYkSPIZPFSUw Ph3YFpqXqzBOBdVZ2qbe7ttccjvSW/t9Ke9A4gzClJQVK42QzrQjCC2DYnC12ZmgIOMw1C HAg0RK0AUvq58KgoZanCYMzFPId5Pog= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-459-kxk2XfuDPpiN2GuX7iYdJg-1; Wed, 20 Sep 2023 09:05:10 -0400 X-MC-Unique: kxk2XfuDPpiN2GuX7iYdJg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 407DE1C0CCAE; Wed, 20 Sep 2023 13:05:07 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C4CCC15BB8; Wed, 20 Sep 2023 13:05:04 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , 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 v2 6/9] iov_iter: Add copy kunit tests for ITER_UBUF and ITER_IOVEC Date: Wed, 20 Sep 2023 14:03:57 +0100 Message-ID: <20230920130400.203330-7-dhowells@redhat.com> In-Reply-To: <20230920130400.203330-1-dhowells@redhat.com> References: <20230920130400.203330-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: CEA1DC0060 X-Stat-Signature: tpay83zyaci3831mhtpecd1eninbd4yb X-Rspam-User: X-HE-Tag: 1695215114-154349 X-HE-Meta: U2FsdGVkX1+RlxVwSb6F7VlViFxWdMlxpfEng+Lht37Xy3BwNxdp73iwKQ5hArz6beNeM+41os0s5/wJImKh7ca0hPzUTLRUDwX6kk0086aTulSy1DCahwPvX011MImLAhe7Nmzk9QJuP0sbyb76P+I0+rpJcxmroOPnA/S3tMtaKyXMqZlso3i9eAqN5WRdV69a3E6Hnin57cYrex3ZX3keH8HqY+6mpKVFEca0qBLpNKABWzyi0ippNc2ase45DP57bK3+7hnNGZQfrz0ra7r+PSGfM6UhPYLAWfgePU40KpwQ08SYpXLjZ3CQ0AIPVhAuFkAlM4qnRLXM61Ypt0c8AnNGccNGxH6d1FqwYI4Q14gUvXcwESoFK6Ym+SdBRNxQEl7rPI9iJod91tS6c1jmGuKdVDb5i9T2fxYgCIvN67cdycTxfqWHWO/JBf/ecbEySQTBX+mSFEvTVYGxHK0ptmDda40fKqUnVeevLEEDyXi59BPNutrNDESyeVOLTZB4XInmLoCmzQFil6stBIo5Gom5FdoVd/ds6jXkUN7Q0MbRs39IWbSocHiG30ERreh1w9pHQeRtLVgdHSGaw+R2okKJQ/Gh0fPBBYcTm8xEIxl4ME5M6ut3RxNuxGFhcpi4NNcsfUPSyw1KCB3nT23KHjCJfi78xZe/233cq4qKFQUI7mRWQddDpMnuk9irvzBKt0sUHMMcCFzChTg90Z5J1KU1/QdJfNeYjzeOH1hE2ZJFXY08pRn3nh1PpxoJUpyqBTjPE6kh7HBSl6pi4TLfRyIXZ99Vuzb9dhvc/dN3vsxVV65hXLPIVcJdS7uOj3k1ViSlMXPM0AVdL5YAxybrB05adqgSxEU/nI4hWa26GQpHdtZ1BaO6KgRZUEBmfb/9sicPgmtQWk7Lkt5+3NVT9bYGGrr+qdGBeVQudiFw4LAnDyeAX5i99hbGkJv+b+hNYUcsH6VgogiOVWY C/cUhIbC UVMC/KAdgqcWkJ0Jr0Uu6ONzBtxdOk7aw30FWEW3oU2zyR94g80erBz1dEpGE0XHjCGNj6xeIkOWqPSJatGOl3+jZv4VyBB7ZHnQ4RkjC1L4sDAdV2svbjY9D3Na5Lrrib5+WNwqhS8SG7KfOqF8n2/Y/AZVGBQC7vCxdp3G1jbbmWbRqLNmmgUJxcTOYnaZp8cuk8LsKDc9HSxpjg365hSNkSgtH78+P5ms5bflieO+W8ba3d5iqI8pWm7ujETw4Iv+hDmDUhofO/b8Y3p/zQ8i906DpzqWXaTr85ijSRO5iUuCWdGeKVcpmXfFx5NspTMg0kJ176ENFRFDDywqw2swXXrpGQYCTsfdHDxiX//h9RAT4h/j8Rks4fQXE1TVf0eWoXo2a6AvnSzkUZHxjuVIPjQpqu6S56d5MBKVL+WXpyTGBhfiOBRrUsKq6W3r8GXUkZD04NEr4HRPNv1rQ7qm1w0nQvkr+HOto/E3HL6Wp3MSFySAHWdJAvD1F26XQcFZ0vdqtjibkGer9UOpfsSjcm/IHBj0wygN+9GAMJbttoLJOku6X7unSLIlMWt0TjJ4fCuFMPgu9az//oOE45MCAPatWf8Qi4wRdGDFjumXRg6/HqzR+N2my+w== 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 | 236 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 236 insertions(+) diff --git a/lib/kunit_iov_iter.c b/lib/kunit_iov_iter.c index 85387a25484e..d1817ab4ffee 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -116,6 +116,23 @@ static void *__init iov_kunit_create_buffer(struct kunit *test, return buffer; } +/* + * Fill a user buffer with a recognisable pattern. + */ +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*). @@ -171,6 +188,25 @@ 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, }; @@ -293,6 +329,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, @@ -868,6 +1100,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 Wed Sep 20 13:03:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13392746 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 0F602CE79CF for ; Wed, 20 Sep 2023 13:05:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A13B6B0161; Wed, 20 Sep 2023 09:05:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 929466B0162; Wed, 20 Sep 2023 09:05:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7AD9C6B0163; Wed, 20 Sep 2023 09:05:19 -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 64A1C6B0161 for ; Wed, 20 Sep 2023 09:05:19 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 31586140201 for ; Wed, 20 Sep 2023 13:05:19 +0000 (UTC) X-FDA: 81256996758.25.47596B3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id AEDD5400C1 for ; Wed, 20 Sep 2023 13:05:15 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JPBaHDhO; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695215115; 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=fIh9Fj3H3rRnydHywvA7K8Amir9a3UPzNcMRqZcgBSE=; b=vwYc/Aj+WdVSsCuoKdJ4AC2n9zSykMY/SPhgoD1TinBxnmEp0mCWF4ADEBCjHSnBTrotTx t8XB3C99GoeF2WscDsVo6UJdg0kuRlC+2EKoI9tVug0aNq/3fosqEQ998xmMn8obSnVd7K jKk1z7h9PDpDYfatQN54DRH64tEZjvQ= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JPBaHDhO; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695215115; a=rsa-sha256; cv=none; b=SL9BFZ0PXmFAiYosNQXjF/YjXwKQpBgiwKxEmfpt13B4pPjH3ZyTdUva6t3FazA3Xa55rT tjn2Uz6aPViBMHXM+PsB2JkxmG+y/96ZFogpvcfpeN1xTc+imGpOC40rmUxsz6g4Yw/N62 3c+4WLQ21fhWf7P0AtWA/Zu7Y3a3lYA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695215115; 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=fIh9Fj3H3rRnydHywvA7K8Amir9a3UPzNcMRqZcgBSE=; b=JPBaHDhOXeF1t5Ic3kZokzSmD/riF0l4G/WmqPKKNx12h5vEzhAfT2Qdh00qJKJJH+fwjk WcYZwSFMtACpD37gUJv9djcolfMZT5B3g6pmJGcRlCpNK0Gq6JvDTwgc97pvOL7dXqkqOT 68sjQhkgomwgLJjfZtiE/6XqkWlm20Q= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-668-tGfIu03hPlqM41kxV_oZLg-1; Wed, 20 Sep 2023 09:05:11 -0400 X-MC-Unique: tGfIu03hPlqM41kxV_oZLg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 C4BB43812592; Wed, 20 Sep 2023 13:05:10 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 05B5E492B16; Wed, 20 Sep 2023 13:05:07 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , 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 v2 7/9] iov_iter: Add extract kunit tests for ITER_UBUF and ITER_IOVEC Date: Wed, 20 Sep 2023 14:03:58 +0100 Message-ID: <20230920130400.203330-8-dhowells@redhat.com> In-Reply-To: <20230920130400.203330-1-dhowells@redhat.com> References: <20230920130400.203330-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspamd-Queue-Id: AEDD5400C1 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: fp9u17uyhk1hrw9ty9u5jjs1inhcegfr X-HE-Tag: 1695215115-545046 X-HE-Meta: U2FsdGVkX1/v2N+Mk0TK2g+GOSOMWgKys9BZeNEiMtTE3X/TXwOe2BdVMMvwtPOV4ohzcQZ8TXslWjhRL+tVSKJZrTdvO/TdwcylC0ASPFo4tsdaHzZ/48kGAifrrDXKDj+cRCMJvkRMJcCzwc/4H5aeMrDw3GHAQzNduq/95bkcpmOZmqZpdd1IQGQsmxiRMDmVmBpcocb7sEvlw1Zza1mQDpLMZE0UEERCXBB/Z8HsWDp9jqxNfNk5gplCbaKF/iO8n8F8lk04FkDoHPCGXn5MqdrSoQpphb6yBX5Iu+txs1VR6kXXc/QWOYliYtD7PKtWWDo3Gn7QSnvP3TxE6NIjoRI/grgF56orcGIJqddzYc2a9lznqOHiqUK0ooz4sgbdMTbg+qRVpNEnldywpJAoSmEXEsr0Llr0zC0u10eWuT8ffKQT/mFW1lqfNAaHcrIaMuj6i5P/psN4qEABBgpea2/J+aEQSa2JZgEIoaqfeZHSNvyGsBdXCADoL1lYyL9RC0te2XEfTXBtOMFK4dduoP9/qHhpn9LCc3TGwpS9u7oXS5t9WaZnHOCkEPzXvBLO2eqa3JYFVJmySJUWrLBl8Qvr1wFXpP2iw/UOKgYIxVEt26xSIbFK4VEoodbjcPcjkQJT69afmAx/dq1Ggp98K8xf8nMIhD+Y9GRrxZO2Y10h01fKZy0v/vsQgWveMmjVjAE2Xlhjw2dtkgfKfKNDYvWxNTC3xitX/ucv/x2UR7gn9zDC0AH9fmgb1yumBbYxQ1e22DCsVOk29ky7vhgtEkCsR1TlYaOaszWGvXE7AmkGUtpkkMbrO5ei25dA/Br6DDiOF0lPiQU/p6eu2lNrnLk7vovy56KFBHfmD637sj0DX7d1HKv7slGnl+UAgeIcO3qYLKXXzHsbQ5l3fXT9SPFDhDuKaVmmnl+Y9JvRhpVpbAgqd/SSd2KmSFwgaCeqfurJxbHhNobL7gH +mZz9jMF A9uC0g1FQTMQl+KmgLeG8vClnc3xUCi26xYpmuWLYLUPzZ/sB2rCpkibjjgL4IZpEI7PTMFMYA5DLTDfxAWGs60cUMulpN4sIrhvvxKY9Rpc3GMDbNC2onOHNcBgIes74LGD/30h5OLBSwIdfKhkSuP/W2IIYBRyNY5YHHeaORx2AReBA7gYTgVk73itO5M6LkDtvnM5agoqfWuA2hr3r54kZ0qdzhUIl1JpA9z/m0sFNf42eAQcny2kQS0sDPESggrrS29xR+ubwapifZztRi15Ia0uVSbyQW2SdTk4dgLYxUnuOu5L6JOLsaZGxKbsHeYZy8twq8aSQtpd5EZVRneuYMeoUXDSY2itH1wbIMdpMjA5qdX8/nq+NenyEOKQIVRXDgGUa4wWsVVvWjbgdytU9hRk21JNdYfPB2kw0pO/xooe2U8z8yi2t1bdDZNt1qBuMtWo7aApV510weBkoE0b0GcAqypTqWu+EQI9Wh1l043VbmqDmapWS59B18m7ltEkjo0eUNmslb4a51mbb2dneUrEzFvnewvvEslSqmlAgxahhya8CiVLhR30p7ydckX5xI85NTAvDcta2+2qyxkyrSpVCZpvYiy9Z7PoPW9Kw1rg9X8L++/RN2w== 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 d1817ab4ffee..2994c3f348ab 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -862,6 +862,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. */ @@ -1110,6 +1272,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 Wed Sep 20 13:03:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13392747 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 35200CE79D1 for ; Wed, 20 Sep 2023 13:05:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B78EE6B0162; Wed, 20 Sep 2023 09:05:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AFDBE6B0163; Wed, 20 Sep 2023 09:05:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 928F96B0164; Wed, 20 Sep 2023 09:05:22 -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 7B3726B0162 for ; Wed, 20 Sep 2023 09:05:22 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 30FF31A080D for ; Wed, 20 Sep 2023 13:05:22 +0000 (UTC) X-FDA: 81256996884.04.34736F3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id EFECD180007 for ; Wed, 20 Sep 2023 13:05:19 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=crim0Bd7; spf=pass (imf06.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=1695215120; 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=YJCqPShPuxX0OSXQWhEKRturENKmTo+NpvJVS0wCU18=; b=pm7WapzQPzOcTCYAvt7w7Bo/+aV+/ut8fx8LoY3SD0UX9tmflzG+5DzJ7WO/nDQ92JW4B0 46Srm31erVXLLyFX/7575lswFMit98Pj+4eVyzfJrFOh17aLu6Zma3vPekGg8/qibzsFP2 IaSGoAI3hd0C10pYYu2/XYEEWbd8lRY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695215120; a=rsa-sha256; cv=none; b=5j4LuYPVbS6/+qItwD4G9TaIL6W+e3XlcbkbjL7+bLaThxBQrwIZOECXIWRj2qQX5Bl+h7 yFfnZh1ZRemB/eSrTsYdaw6QuVIXc06ZPbSGDvyNGmaztcIF4C4MkklisynOfoHTRG3oLJ 4zEN0GyPl3AqceDhgosSGVa+0Y9+r6U= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=crim0Bd7; spf=pass (imf06.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=1695215119; 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=YJCqPShPuxX0OSXQWhEKRturENKmTo+NpvJVS0wCU18=; b=crim0Bd7q8XcIih6T6ycIY4Fz2F3YwluOwN0NWyjxSfJLOZjKCCczc/yN+X7IDxaXetyAk /TZIuVtQkyLHr4UJNgI16CRYjG70bg2gT/f314SyQxvNrya08PxvW8gCRyf/RQWLNHftal OhCNKs9Ee4maBcpEIgptc/BQpAMpVR0= 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-688-aNGlfMQdOTe2VK1zYWIPzQ-1; Wed, 20 Sep 2023 09:05:14 -0400 X-MC-Unique: aNGlfMQdOTe2VK1zYWIPzQ-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 C3D67858F19; Wed, 20 Sep 2023 13:05:13 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7BAA02156701; Wed, 20 Sep 2023 13:05:11 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , 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 v2 8/9] iov_iter: Add benchmarking kunit tests Date: Wed, 20 Sep 2023 14:03:59 +0100 Message-ID: <20230920130400.203330-9-dhowells@redhat.com> In-Reply-To: <20230920130400.203330-1-dhowells@redhat.com> References: <20230920130400.203330-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Stat-Signature: 95gk8be9m4ksjrsom8i9pgt3ua66uqh4 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: EFECD180007 X-Rspam-User: X-HE-Tag: 1695215119-527137 X-HE-Meta: U2FsdGVkX18NBoG/iMJ0NBVrHFUHDL0XBESWDgaDjvOLPu2nrl8uP+bsCtUsuahxJMS43UGuTq3MlsaoTYQZOVBN9qk2BcKOmDl4hTTCDJNFi67kH1moPjAT8mN9Lwky9Hmt2EcKhUYlDl+PzNJfDoxwjvuuo24snKG2XFJbGJpNvkdHrV+LnthiXu1J1usWbd3rWWbio0o+VtTIehFW1FMlhwA6Bo4tWhII3513hnqpXWYBk/UnfZo4fz5Y4JfxAEf9FSXPm8yS80iF5clP0i7nBQhU4PgjX3iRa12u+J4fQJHUukIfPrgwOr4V0KB1DAHZ4VQWlUZVARBpCdXpSuU9lkMTGEBU/75VLf6tq8hnOLGTNiHh0p1sbhszd9rr1sxytqy9br12cGc4QXITn7HeMH8VrmacNPo1QqmfN+4eLfnTR2TGHpG0T0RJCJe4Yfd4yY4A1SDyheFdjdSwuhhck0CbcYNri1Gd7TxQ1b6QsTJFB2SbM0fTSNHPL706frDHd+MkR9t3Np7AGi3pqJUtiLtrdv7WxpmYGcBR3hT/OJF5X3TxKakz67Xo1587muvLsCB1noscw3ZiyTtpUW1i3CvoW5gZrIYxj7ILd4vLEMiWooXBLahY7Klp/hQM0rlPRveHmBsoS1qTpvYs5dN/sNUsas0jWw0iBuvHdKA5snEls+bRVDrAU4T7nB/nIFOp98Qr8O8j4LgFhQs/y7Y00UpdE3P1qlp4YaEcK/w7+q/5fyROv2ZaGRNRVwV3cB/Y+F/6RwyMvo+rPf2MYMdsWR9VXzbpiLCITZCyROhW0r5iIMpxhwRVvR+uHP3ylhWDy1YIr9dC6RxxoI8xPUrGKUUE/ORlvYoz5lQuDHCAVSrLw4buMemwTTiBytEat57p6x9TYcfC6GWJqkpo1Q2H+iud5sB220Y16m4aodXU11JNc96/mNnBxUDJEYUHZHCsxxCGPVqJQpOV+/W 3BAymV0m N7juhBh2Kf/I6JoHdnkRrZdSHod6nY8CeuyLBrP12gzZJdV97i4O7Er2+o9XN9OiQ4xALnZc0mMR1VSw6T2gUXleXDLXz2sxvPqnQJ+lkoAGPISwPp45lIo3wSdeahy5K/Pl17Z6ppVCJ4Khf9VLfsx4/tS37K1Or4WGtt4n2MCkbc/q3ZSmGZSc0YTIVeH6rO93dACu+a/d3B1MmYgUnCVmADE1XepMKpXLNAKqySwraqqz2+wXUdx9DHiBFUmOc6REymhf9xMZ78uM/KU7nqyAOJNWujOvgTV1QABu9eZfj/wuyFdap4B2MRhqfiaw3ugazcoPZu10YCkvC2SLTLsXVGbQfUqyeRowUoYYky/nBGZz0XNcaRUydcyi/jKGzrmI5b3egbC9F/+GQ3SVYDM248x65cURAO97mJaaUx+xdCbAmpRXgeeUoyazqKtwB1xwXPx4Dnj/zxD71mCM2y5y7lLpT4waoKej+FqIBXS68//7fP8cXKzHTgbNOfITDDfAl 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 2994c3f348ab..17f85f24b239 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -1261,6 +1261,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_SOURCE, kvec, ARRAY_SIZE(kvec), size); + + a = ktime_get_real(); + copied = copy_from_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_SOURCE, bvec, npages, size); + a = ktime_get_real(); + copied = copy_from_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_t(size_t, 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_SOURCE, bvec, npages, part); + copied = copy_from_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_SOURCE, xarray, 0, size); + a = ktime_get_real(); + copied = copy_from_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), @@ -1277,6 +1524,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 Wed Sep 20 13:04:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13392749 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 02A5BCE79CE for ; Wed, 20 Sep 2023 13:05:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D70716B0165; Wed, 20 Sep 2023 09:05:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D28EC6B0166; Wed, 20 Sep 2023 09:05:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B4AD16B0167; Wed, 20 Sep 2023 09:05:26 -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 9D4066B0165 for ; Wed, 20 Sep 2023 09:05:26 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5DDAFC0734 for ; Wed, 20 Sep 2023 13:05:26 +0000 (UTC) X-FDA: 81256997052.07.AF2CACD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 8FD69140016 for ; Wed, 20 Sep 2023 13:05:24 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LFy6dDPC; spf=pass (imf26.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=1695215124; 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=WKL59oxitSx6DOUyNJ+1H0DeRSBlY0vVZI1oz1R1zFg=; b=EOWOc2Ilmd9Fzn+hfQ2ztRbZernAdsT1KF8MaEqAI4MkytHqWrlS6NLRALJWILFf+DNkwD YVmwc8j9lFMRsxH1mxYPrkLOHgow85c3Eovj3jtfKuf40IM/XAoyoiIvP4quV+R4yEvlJC HSyl2EO3MIotvFVNdwaUuFYzhKDdlMY= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LFy6dDPC; spf=pass (imf26.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695215124; a=rsa-sha256; cv=none; b=b5OrH3Ekx9AiXAx6h7ZxsnOeFr0vnOTEz1N9hRSvplMcCQYtqXAM22X5dnO4l4bsPzsuC5 5I/nX+qXoRt9mL5n/8AqTLjw/hiiH8lneXWBUBEEUde0aw5pInIz4uOlOfIpmNwN2RlRgk xBmfOJ7j9nqm17MyNEhREIZlZruWJJg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695215123; 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=WKL59oxitSx6DOUyNJ+1H0DeRSBlY0vVZI1oz1R1zFg=; b=LFy6dDPC2tomJN/FwHCsi7jJ6+BDP5Iv8j50RF5G45BBRr+IZ7ui4bFYa2MnTBcXQkLxW9 liu5EaAEnvdTOskAU82xE8D99sjB2jLyImXzHsX4KTa/2SQ0RXCO4RvOJ8Rq6lRmt8ryhZ RbIbku5qh52ttdXH7sIRjwLEUw1ojV8= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-653-5VCNNxRlNwuawrr7coWaQA-1; Wed, 20 Sep 2023 09:05:18 -0400 X-MC-Unique: 5VCNNxRlNwuawrr7coWaQA-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 D5BEF2999B36; Wed, 20 Sep 2023 13:05:16 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 698FE51E3; Wed, 20 Sep 2023 13:05:14 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , 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 v2 9/9] iov_iter: Add benchmarking kunit tests for UBUF/IOVEC Date: Wed, 20 Sep 2023 14:04:00 +0100 Message-ID: <20230920130400.203330-10-dhowells@redhat.com> In-Reply-To: <20230920130400.203330-1-dhowells@redhat.com> References: <20230920130400.203330-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspamd-Queue-Id: 8FD69140016 X-Rspam-User: X-Stat-Signature: g93c4myaex9orfkfagdfzckddyii1d4q X-Rspamd-Server: rspam01 X-HE-Tag: 1695215124-68545 X-HE-Meta: U2FsdGVkX19zdvYWv6Mwa0wLXIoShZguWoXqRtGL7pzp2X4CVAnNZkWFIaMWGt8Bl+h1wBblNumR6FCgUt9n3ives4CivjsC5+fF0rc1L/AhOuGRYC+7CPNW6MmREPmxYmgfV9G1NBFwdSpNWhXXIdy2ww6wygRqgI1dqOXxSb42gS0icXX/qM7HnUe257hBEUEK1fxQqB2/dCXmJVUz13gGXtSXmGoYoT87HrQ1CMdwJGoll5eiSazka8qa8v2FW1WUbHZcgWSfgkHQY3jjDNxKFp63STz/s7G9U+UFDQ/+8eAfJ9ckYEncjsdAgCLQAEbg40YFTA294Kdziku3LWRXbAGI0aW0go0y+4vgFJ9Lbs8fWvVvbD9/GsTkQ9O0dxqnXX7MYO5NzAUoQEowwaE+45swT/bZ6AH8SO3GLayh+oz3DL1AwKIvyNpEHn+n6qQDGQ7TT/641g25SWxwP5+vEsuML5MrBsX7JG79QEYJzoU9qWPBzI1rgiplOLseehxxP9gHMXDS4TlOXDWubRUEcds1yuAhMTADG8fNNAqiHz1mjs+dSrvZ5QeMo2LVgtysPsxwpBm3rQeenNyDp+cl5FG8M1OAQrZnz7JZx5/lbWopv84WPFXPhBKwFDckuBdvNDYPkMOQA9gef5SVK+re9UtI508osovN5onJVfDTl4jKk5QdUqhu2G1Aj9sSeNM3SQhEiRXUDCIhqfCIUxpk/9DV99hC8qrUhes3lZfPrfq3gZlWsdKkRlmxKtKydRPZXVSXVCU03Oz50wzmJuOxzJXzBB/EZUktLpD1TBk4AOcY6r60mQYWCSzk9zgXNsP+gIbLX8CW0+fGl6VWKfv/Wcce5xVq6rhhyXZDI6W99AYO7HIc5983h3cajO59irMeeLtGOD9nKKVUHhruo9r2/M3N3TcVXoxNFU/5hloX9ZA0q7Fvq4w1t0D0DOQHFGpT8zr38+DF8+gnX9+ j/R90WIK Wo9EOlh/1yXkKzcSbCHxON/DamAz9b2hTsoDmqj4ixY9BnVZ9Ff8iMvoOWRqZHbOPIeSi44g8dpx7WV0kVgTtm/MIR7WWnf71OcA7/VL33c7sU7gx0gAn14bTVyeZo38CYrJYWWo1SQ0s7ySqlWGFJ3pO3Bifqw8PDF/OQjbQqEqzzj1/dWUfPlRDiw2Pq6XL6d1IRADzrT52O8u8Bw7OraU3qL3UPisavtZs4jQ/iC04dTNXPqSwawp1eg6hWvEuNH+xvIb6vowRb5vkTpg4RZgFZijcg17S/SpMPN81Xn7oitZ+EGvmGC2CD8l/pJ5D6g23DMJoILRzL9SELVYpHTc/jNp+oL7S07cz2bGz3i+U7O5twZQrDKBqFyuvcvrmQgrQfCP2xlEquqml+DdP4GVaAm8nKvgG76N7AwJdr4Z675lfZSS6C9Ll6Wrh0hOesRLpcwoyBKjwBK/i07+xB5HAcxbtJ8jVYbmIk3EoWT8aT1zPxpFJUwAJZ6q8U3xlsNkpLuUAKux1eckHFz7JDKkvg+m+idaNWgk9d0ZT/hPBl3vem0igT21UcfY2HnR34dg4gFBYo7JSE6ec4VwKHjbnaBPKA5ZFAXHPkiGTnPjXl/lzvGHlf4K9lQ== 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 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 | 95 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/lib/kunit_iov_iter.c b/lib/kunit_iov_iter.c index 17f85f24b239..4ee939a1c5ec 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -1324,6 +1324,99 @@ 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++) { + size_t remain = size; + + a = ktime_get_real(); + do { + size_t part = min(remain, PAGE_SIZE); + + iov_iter_ubuf(&iter, ITER_SOURCE, buffer, part); + copied = copy_from_iter(scratch, part, &iter); + KUNIT_EXPECT_EQ(test, copied, part); + remain -= part; + } while (remain > 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_IOVEC. + */ +static void __init iov_kunit_benchmark_iovec(struct kunit *test) +{ + struct iov_iter iter; + struct iovec *iov; + 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; + size_t ioc = size / PAGE_SIZE; + void *scratch; + int i; + u8 __user *buffer; + + iov = kunit_kmalloc_array(test, ioc, sizeof(*iov), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, iov); + + /* 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 < ioc; i++) { + part = size / ioc; + 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_SOURCE, iov, npages, size); + + a = ktime_get_real(); + copied = copy_from_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. */ @@ -1524,6 +1617,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),