From patchwork Fri Sep 22 11:30:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395600 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 8AB0BCD4F5B for ; Fri, 22 Sep 2023 11:30:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25F7D6B02A5; Fri, 22 Sep 2023 07:30:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 20FDF6B02A7; Fri, 22 Sep 2023 07:30:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D68E6B02A9; Fri, 22 Sep 2023 07:30:54 -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 F2FA86B02A5 for ; Fri, 22 Sep 2023 07:30:53 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id BF7341A09CD for ; Fri, 22 Sep 2023 11:30:53 +0000 (UTC) X-FDA: 81264016386.06.C55F118 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 0003C20008 for ; Fri, 22 Sep 2023 11:30:51 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Zs3MRY+i; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.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=1695382252; 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=hB5AVSwW/+LdftfxJSj630jl9BzP9wr/wbgZiRNVeaY5F4umsOuB8qaIq357fwhzPt48za ImgyAmzgBxRveSZzx8LcTWcCfsGQw4JNQjdZuHUtzSaEunpMUuUJEdCHNM5/P0eMF859ix DlqqMwWKpfaIuriujsLvswBP2GIUPaE= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Zs3MRY+i; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.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=1695382252; a=rsa-sha256; cv=none; b=bHUcyhftkAhhR4RWb7LPqSkHUYxROrhnRjQmSRXj/ytf2xLyfKZ09fQa0J1nZlbPQrzmXD YgRGhgs2UFcVTTP49vUsFv2NNADle+F+u2TP5qVoOVHCH+Jp9lvxLlYu+femHMSZyAWxtx Lzk7aOeC3rIY4AX1pm3ELaDR9Fq1f2U= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695382251; 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=Zs3MRY+iMI7HXGTyjc0bwPZFkeqIthFUIJnuc2sBHxGHp8BLdanaxWXdInOnv6iDTatfth BEHbZZdDxfErDfANxWbclI/3e9v5pBavMv50/znkM6IjXXHIOI+8G2p5FzqPPcVJKiwGRA wDlQr05nTgghgh5ikJSfRWRz6ccg9Yk= 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-653-KT0GdNRTOGGtecP5LMMYMg-1; Fri, 22 Sep 2023 07:30:47 -0400 X-MC-Unique: KT0GdNRTOGGtecP5LMMYMg-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 0347B801FA9; Fri, 22 Sep 2023 11:30:47 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id DCDCC40C6EBF; Fri, 22 Sep 2023 11:30:43 +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: [PATCH v3 01/10] iov_iter: Fix some checkpatch complaints in kunit tests Date: Fri, 22 Sep 2023 12:30:29 +0100 Message-ID: <20230922113038.1135236-2-dhowells@redhat.com> In-Reply-To: <20230922113038.1135236-1-dhowells@redhat.com> References: <20230922113038.1135236-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspamd-Queue-Id: 0003C20008 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 3mwcm93hsb4tdncf7pnyecxu7rmao1jw X-HE-Tag: 1695382251-599139 X-HE-Meta: U2FsdGVkX1/0vFowmxTud0kShnG1xdkhGYbeELvsC2I8H8WWZ0O1DsH4DWUdP9+dpawwbDEV3fxxFSb09DGaohqsv2S+0hmpKeL0nOKfMmDuTUp3HJpndA3z3suoWQzofsUodBMs6iCk1Q45mnm2zMTd+gGxLyQZiVuurwuiazbHpiBJJHXBaWjYuJGEMgtUaJzGSH9J5AxLeUVSqoT5M5pnlr2fvP87v+njSF4OfCPX/f+heschgNd1w0kgQ4Clqn2owKTar0opbYN++cDUf8u9+8n52H4oRXCSypPjbwksojzsFdlOpuQFd+Ko4QeBwO8vYp9Xr8tXBvl9BeXeG3+oHnNlkj6vSxFjFTi0Kz3Jckv6kLykbNnQ2tLteiSXEr/jPn1ItvYDDoFsMQKDPYqrYz9ZCQbJ0tR1c3j53hacbarASKJR4OoA6FFe/DyZT46GDBnP0Lbzj4OdJJ1bEyxFoHhIFk6+OWuffDStPUFM0O9Qt/622lVGufEbgcDkOiBWVCrz1cdraSOG78HRj9BqXsxo+fx8seiksBl1Hded0hpbj+9GTVDVWfYQQetKQgw40lZjx4MJqOSQDR0mJXXvHBChSae7MGZnWdiTi/5rgYOJf295ydS18AYEvl7t8yxigIlU9YFpCd1rRSBJVlxfKj2YxMsnXpldeF/IyqaTiP+f1XWRV8updPhqNk/e2TWxZLeM/phDowj5pB8Cj2xA+PsV8jguBWd93gCeinEULnNTE7w3jf6hKOirEbj/Y9gxk83NDSL98n2dbcGmAje22EQfejBDPxcVqnncxVYhBKJQDPtf1EdJTAkacW/eBNm9SYZOmeCOqlLHlNf4PpTJe9xvd97qwhmBw18tL1VUecSQFGa22wnZ3Q12fC9v7atAoDOweAExt/MeSyIebkMqSUENyxFAZXbUNJxHwc8zZJCMlM0xG49yB7xPF0NeI+27YuRmQZC7k/c9gVp 29lyu6Hb VQR9pkDGoqQghRVZVYyf9AqGqbTJ4AFYY/xZHXiY6MvI+6TDB05jFev4fSQ/QTtEfQNrfaodY1JFGzgskAyzGo6JInCXyNAEg4dixmGFFROpB1k0vTvykwj9sqBCr3znY0EyqFq6Lp5tlFe7qKel6IeeHuFGX/gePpxlnQVPj9eUy6+d9oYKt6FyG2IaQxd7sh4q+K4gEFkPN6MJA53ir0UffvuB2QUqxYdS1UhB6Zap7eBFNMX7MLubqtGKYBNj+4Wka2fif9nVU9iWQVWLqH9GFyK49Rq8vjkcM595vKZbdlr0MTOblEPlNpN07AWmyXrvBA9nySFKfymksA5V3tB+z8HOQ0bIMk/MwZmNjF4oFL6QXlU1mlSuJuWy/jTbsyC0yrnIPwNCTcztTHZP3XZJel/cRD5j4Nid+PUun3uOCT+bSN2/Pdc7RedhY5NwgrVN9w2ITybVsrieDFHjsmT2XOiw7+GGXsWIVSDmUiIevKCoE4qjPs7SJN54bqu5ZRevKnY18XG5LWVAe8WIRQFzVrdaKWsNOdv6tAFCIvceTuDgAxYFMXmclpw== 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 Fri Sep 22 11:30:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395601 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 611B7CD4F49 for ; Fri, 22 Sep 2023 11:30:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E93BF6B02A7; Fri, 22 Sep 2023 07:30:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E43A66B02A9; Fri, 22 Sep 2023 07:30:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CBCFA6B02AB; Fri, 22 Sep 2023 07:30:56 -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 B74536B02A7 for ; Fri, 22 Sep 2023 07:30:56 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8D89A1CA3B1 for ; Fri, 22 Sep 2023 11:30:56 +0000 (UTC) X-FDA: 81264016512.22.15E905B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id CD7E440007 for ; Fri, 22 Sep 2023 11:30:54 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IdwWJ8Hw; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.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=1695382254; 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=qariRkWO7HO/QF6n4mZI1Et2l9CXp2nNo8v1ZVi7D1yyG4fkaiMnw/5P5oYlI15wE0pbT/ 4cAFDb/gHUvcpDOCTKcLSinNk8t6QN75Kif0cVf+A6UZczVw6LndR2FIe0CW9t4MQpIBDd ajfI01Ou6F6OAqRYfp09hUh60jykkpQ= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IdwWJ8Hw; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.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=1695382254; a=rsa-sha256; cv=none; b=YCy43C+7zScilACzHJM6iOs45xgaFugVTNh57dNBWdOsY2btVQu9Svdg9nNvwNb1xep6N/ UpRknB1TS44PmSDm2MZ1U47QEoLqfE5mc9j/xS8wqopNo9H1DU6Nkc6XfyS+kN9e51jP6G JIb31m9nPzHT3pkQpBPRx1M6UVAycq4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695382254; 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=IdwWJ8Hw0mtpjk2fvOCUSsmxyRbES+fXvhr5KKUPBJpXlih/1C/mBbh742x6MNqTnCxW45 VN2NB4Wn8H05FdpWqRX5k9lWzpv6+dnBLHCLtqY79tWT0ALVHMqqPQ1AR1fsjeSuj8yQSn tW8GBDrqZYeMr+uxNIE8frs4Vscv0ls= 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-571-n3IXvpDCOHC9CZbgLDRaEw-1; Fri, 22 Sep 2023 07:30:51 -0400 X-MC-Unique: n3IXvpDCOHC9CZbgLDRaEw-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 0FE8038125A7; Fri, 22 Sep 2023 11:30:50 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id ABD0C711282; Fri, 22 Sep 2023 11:30:47 +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: [PATCH v3 02/10] iov_iter: Consolidate some of the repeated code into helpers Date: Fri, 22 Sep 2023 12:30:30 +0100 Message-ID: <20230922113038.1135236-3-dhowells@redhat.com> In-Reply-To: <20230922113038.1135236-1-dhowells@redhat.com> References: <20230922113038.1135236-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspamd-Queue-Id: CD7E440007 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 95oh8uchho11yn3kmj9gzftn96eh9qz6 X-HE-Tag: 1695382254-463403 X-HE-Meta: U2FsdGVkX1844sOAR3KzkohgophvZbpVqybSKRwz2o5jVywzOVkC6ApMVGgCODWxnt5c/0jUM7Slr41eQ4ao37FulE+NxtEHZityU96aA/1wK94AnotXX9l/GdPf2wqep+B7zVVXMj1iaiuuEZpE+EwSXK5ppi1HSrXYAEWfnZO8R7JfwgItUr0kKqFLWEpDeU8bkMrfTxXNmHeXj/+1M1nhshEnttlF/573RlVqm9n92BDtPgiVIbxxJTMi5elA81PDKPWuS9/cOZU1+wBP1mrH7AEqUV2UIQhznU497tTsPv9IaYkycDQlv1V6fjqGufpp9ll2DQyVHO3Mvb/s83Jm9S+w2KzfXTAv12HmhOtAsmr5S/iRbGqObFS9kgFgIftc4IDNUzuIAUfCEviS5/yBDh2JlS3CX3a6EZ8e+E/40wGf0L3RtX/5OmFyg3KytL19SJkIh4pEkHvnuBanmLMZ0xXG/8eGY3fi4A8UU6cPQl29qkVp/dhvervTCtBQGPScTYdDj6j1Bj214HFUlmYAM/A4S8GwXdeYyV+9JKcRWlC7npkGL3c7uADP2H0PgWIgkbo+t/LRnGJNjggrDVZCa0NjZRjyfv2oJhgxGwzo2f4aissZgBBVwAfOyvMid5WUTqEbJV+q/UExmf94CSBKqULPT8zjqvxaGHxpOEa4FUvYPmGPVitEiVafOzFvFuJm8IdopS1evoKdVnbVw3YcM47SAmnZv8KJw6Mywh+JSzPASynSgSPMVBFKIDNqOJ0Hkb1Wo9FUD73Np1mTcxiLVzx9PCOEJE6mS4Na9fp//7xASx0Sf4RUy8xep9y8iQdqGiCZWUem45PvJS7A8gDDIm3CzV/D8VZLw16H2n4GByVpfp4g/g+NQPdu9MJnk9J9yKOvn4dEtQelUDWC39aB7GhjJ+qvwi604rc50OkPNSRAvHm7buFc1ofCVI5kfnEZ5QJ+TrsHTV9IN4t bHin7STF xsBADawux9e30pNQthto9zssygvMcLChYyL+koQoWgZ3ueqhXY6XM3loa/B8pB3Z+LsE4y1C3qz/g0xeFCTA8GkpYOWzcpkVajnNpiLuRvfePLbFhOR2ftKhLG5zPpBLfXf5j5btrAL8p6JXwiEk+4haDAumpSYHpoAUrUrIOZZzgCVuan4SMMugSs40iYJQl1qKEwmR78k3PjVilcBf85csa6ludcsc8WkSLuTY7V+fG+qkhdvbaOj9pVIfAj5Yzs7CQTflyo+ls1yZej/yjoGIIVQb+BpR4poKQUzz+JPCrJ3pkGk3pR+cbGTyM3I9hzf8Hdmg8T/Bm3gSsA8zzuDWBUGWDlf0sfBzvzqnBcgDMIS2zVuLF1Grnd4jsJHzaA5/tzMQ20AEpH9h7q5JCxKhAW9gGTIzaNMSTIQ1I3NQeqnuyHQ6iad8KI4eIleEgDXW2M6cDymyeHlduhLIhHQqGDGNOq7+zjueROpZVB+UR7tyS7hk/YIAiwhkoliGUGQlk 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 Fri Sep 22 11:30:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395602 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 F0747CD4F5B for ; Fri, 22 Sep 2023 11:31:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 741406B02AD; Fri, 22 Sep 2023 07:31:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F14C6B02AF; Fri, 22 Sep 2023 07:31:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 594486B02B0; Fri, 22 Sep 2023 07:31:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 43B966B02AD for ; Fri, 22 Sep 2023 07:31:00 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CA1B91CADC5 for ; Fri, 22 Sep 2023 11:30:59 +0000 (UTC) X-FDA: 81264016638.06.4C6BF10 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 06E5F1C001B for ; Fri, 22 Sep 2023 11:30:57 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TB9OuWu0; spf=pass (imf18.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=1695382258; a=rsa-sha256; cv=none; b=UwNEssfQCXdyGDS5VypkbLJ9tsoiqqua5f1csEuMGoJ8fSVEjwd9ZMX34KzhQjqR6PpBQ/ 4XSiV18YQRd3hfymgUegWTDb15hVeleJhmXJUML9KeqhB9kMXVyIgBDRwiyo5Aqc+l4fUW FDlFreeVHCUWIgCuGA+JEpOu8vbv1o4= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TB9OuWu0; spf=pass (imf18.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=1695382258; 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=3+7dlsgFN4LOM+pCZZ+hwh9k0FPfND0wuyjHP6wRK4Pw7MCc7uQ6MPvqG+Nj+mYwswxrtI Y4/ifRITaHJjVz0sB5Xa7RyYc19z1hjk8mSSET0h9hgQAlbZdqQCJVCAtOCI/i3wHUMUcK xaermOKTsWCsbdsnhz4kCbrqCjZWfUM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695382257; 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=TB9OuWu0w9d/wl5djx/JGdvfi8IC2wUJBhNsBr59dTNQNVgzdiSibAsDvfKSjuv9Yxhy2q 0YqKO22zv0uugHHUQIRwQtJssvTLyLnzJz7JcYYV8AXQ7oGN9GAdLXQpYMtZogzGbZyJCj /y5RaCj5+hCPxhgqy/xDQCmJmdfoVsw= 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-642-sXVlNUA6N6ygXS-_SjqBww-1; Fri, 22 Sep 2023 07:30:54 -0400 X-MC-Unique: sXVlNUA6N6ygXS-_SjqBww-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 F00B080349C; Fri, 22 Sep 2023 11:30:52 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id A3DA720268D6; Fri, 22 Sep 2023 11:30:50 +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: [PATCH v3 03/10] iov_iter: Consolidate the test vector struct in the kunit tests Date: Fri, 22 Sep 2023 12:30:31 +0100 Message-ID: <20230922113038.1135236-4-dhowells@redhat.com> In-Reply-To: <20230922113038.1135236-1-dhowells@redhat.com> References: <20230922113038.1135236-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 06E5F1C001B X-Stat-Signature: zi3dja81sznhm6n8m7adxt6wxxq4jyrt X-Rspam-User: X-HE-Tag: 1695382257-57458 X-HE-Meta: U2FsdGVkX18Q45ATuvUmDuMPOBwPW/HCgffKj6aLRqsKtYcWnKPCcziuWKfclMCuB2IXYrs7k0u9o09PoChShjN+luVgJS+IYGy5L95Ot5V4jKnm2go5pNuOCt0ViGqGhCIFJXjh8wOIbw4CY4lngAearsyrN0dPshEHwCX6gW9wKOL1KoMaDgUxLrnVgHeV8KqI3FBZ2aqU2wVIJQdENUs+jXNvN/0xtl5wvG2ePdDB4dMmyqhcyVsrKoTURymuhcd26eRniywWTnMpSAM8XGyLKsiNFyr+zY2SPG6LD88bI+8sI+Sc3b14/RYPFxeXisHSo+460fVA8aVB8cV6JeKR+YXhuizuh+tuQcwRthbDADvqvuMzNH9Kcx6jpmtnN0Mug6gJb+C78cCOz9yQPr4gLhxfit768kiPEUSBsQJUMtrWA+hROcC/AJIAu1gjLevyEq7UXA1bbHl7QwA9NXvdtwZWzZ7GTV6DAkf2YnRlBoj08ooirxUH4BdwA48Zw0QkB2Wy0KYYrnLj2QSCg/di/pM4+XJrwrkeiRauOEpDVb6FjHbzgwtdjbVdmA7Yl0iS5paoAn4k7moBMo+piCZPMrjdARnrGhY81h7CsASgbxyr4QnKhMjpLBImCvqwlkwk/9JPKH06n0/rq3PGN007T8hIGbjXkXR5YopzTAtbkGuIWH0yJlSoBHQAupGfBxipsb4BsoX0ScA5AlbY64qhMUIWDLsu+zU42C5cEXg4g4+KvkGQd6kNmPhDK5Dfe4idhu72YVA+yC3ATZtmiBdh9DKbT2fIDYAZveYjP/FR+Gx6Wok4AsCFl6sRUlX759zSQLR1O0lBPS76culrw/DzKhxifdqM+A5jnvitJWE5tGDcONg+sNpC/9crKlC0gtt8zw5ERvESv24OfSppTlgQxHp1VVl+oOLtaj2gPFOoOG/pBj0V00d3TIndiPK4H8NS90z1P9o8sCYdO5t vxSZZ6vE 9RZDeK/1uD/SEQOfC6DcGhMylZn0TYNkmiRmZH+6/e2ZJJTf/Tahy9P50BCaICuz/LkOzjYJpnpiINVwF+xiNVjt4rDbdpe+4sG0OAInkiQD5JztuBFPxFTEMZsK7olXK6zQjh0wGW1YkN7cXwK0u+xzMbMDEZFhW8Br3nqCzAMFNvzO6luCwf/M3smUCSRxTtNjycQP1BL/eL3juFl9LL3tVFcylwvarUZD5y4l4R6z0XbMWNGhkfNjDxz2woBsPmQlZpNbA5yYg3+YiLSFH/QIRXoKNo0Ho4RCIi6FzzflbctkGtlbSMtazw65Co/ZGK192eaNGeExhZ5TI52HMvYnl88cC1aSKGvLC7zPas/TFSUzY6tODAcJ38s5O2seLfuOvglLidfdtF54uGH1FLoXrHSvcIasbyCabBejg/hFc7GyTXme8rLy5HP7ZzxEMmIMHUD0QHRWfj6JOlofiAHbgbe/8OO+RD84LKiihNiFWJAMY6J0oB6Zw6C7qJlZGX10U 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 Fri Sep 22 11:30:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395603 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 4BAF0CD4F49 for ; Fri, 22 Sep 2023 11:31:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E46786B02B0; Fri, 22 Sep 2023 07:31:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF67C6B02B1; Fri, 22 Sep 2023 07:31:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C96AF6B02B2; Fri, 22 Sep 2023 07:31:04 -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 B5DED6B02B0 for ; Fri, 22 Sep 2023 07:31:04 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 839F2810B3 for ; Fri, 22 Sep 2023 11:31:04 +0000 (UTC) X-FDA: 81264016848.01.0A8D3D9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id BAD1120002 for ; Fri, 22 Sep 2023 11:31:02 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XnkH6T6f; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.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=1695382262; 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=KQlRVJ0NF9mSb+Wdvk10nccTR9rpXtRM8KgcdW/iu4S9TFLZWDCDxDGczKk05AOMs+ZHor mbB0vFE3znr/90JhF8RHegJCzWI7d7b+TnLnNwe2mVswO9OqlykiabLJI4kE17bAYl/+CH WOsUfC31NOncdrHbSit46J2El2DOij4= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XnkH6T6f; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.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=1695382262; a=rsa-sha256; cv=none; b=R6fNEAT4WoRAyf6o8hixl/rwJN6AyOIOaK7PjOPLqopeU6wgiefZpoinZtHQA30kIRwhxl AfApCcmOD1nlXumNQwoiDn0GIGEF/MP9GYNVm5hWbdcrNXGYzULrcXNaZS0/A+NlBnlLoC tRDdDrINY6KwHCJfqHoR//xBP3S0mGA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695382262; 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=XnkH6T6fwPwgW7tSguvVhSSO7/4h/FWszm0Ppnrhe16r2UhjoADxWgyJGTkq72SsNQAUvj zPTBjIFvHtSq6osg3hTxvxIXyhg7MdOCGbSC6k2EoxCPGMgV0+CFK8XXKldWdlF2c94HE8 pXfv9vA/XkNr5ceYzJQxeT8BhZmYLbU= 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-610-ABTkBwruOi-eHMhSCrIRAQ-1; Fri, 22 Sep 2023 07:30:56 -0400 X-MC-Unique: ABTkBwruOi-eHMhSCrIRAQ-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 E6A04800883; Fri, 22 Sep 2023 11:30:55 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id A69D72156701; Fri, 22 Sep 2023 11:30:53 +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: [PATCH v3 04/10] iov_iter: Consolidate bvec pattern checking Date: Fri, 22 Sep 2023 12:30:32 +0100 Message-ID: <20230922113038.1135236-5-dhowells@redhat.com> In-Reply-To: <20230922113038.1135236-1-dhowells@redhat.com> References: <20230922113038.1135236-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: BAD1120002 X-Stat-Signature: bt9d7a1pfyyw6mybgjtexckmfj9e1qts X-HE-Tag: 1695382262-400033 X-HE-Meta: U2FsdGVkX19dST1fi6TAS6iIBFKCTzqKWaj+7z+H+w/mLbWgGJBsEjTlxrirgzWyfD+AcgBqJVPpjbVtzOz7NViwlEXfIAfCaCzSOT+zIIyTXoKeNi9UfGksxi5wqZJQkVQ6Zztm9YmOWwy6n7wTz4qeykgN6rjz4wx2d5sORfARswpCi8sBY3P4ASEFdz3tEbhGsmdjbz1/G7L4raPVN+NsQylGTrDZEIrKO5TzaQV5+S7apc7iMNWo+u5epcbhCQyGNFbJViRfaI3i8guNPeh2WfXRkXeIf0L16ZCr/RJjraFiL+EfirVzPiTJ5i8QBhrJsECoJ97SR6hnbJgHkMALA/Q7I/6PzVvMoeROtD26Swmy2+4IpuoYN8jhj1g+E38Dqw5yo/5mvkcuWoyp6XagLm6FVKr15k+9t4tsrbyW3OnjIhNdCgSJcrCh7iu0FM1iOt1B6sBDKKVQPEUZjJjRN3KSO3s92by8h3yy5SbRgkAKGAbPH5rhJtgQpx/mhYppemVOJuPZOLa2zRFPrGn8nbyO5PLw8LvVtWDMrZKpqpWIb60wxZU8eP1ne7U8pMEte2rBkrUwA1v2JXL12YK5L6X873rZ1MbfgTMXboW7gM0bO5EnTV67dIAy/5HqGtkttoSsLh6rmVH/LZVwqLDPAMYXKXBkvAsi77D218NV5SeJx+G+Ugtx4Ftf95LU2TK56aFug9BdI+rJqo0k2TdVNY93QuYexLhnu3Uc0RdOlFpTDBJrJGDomIyOELmoozKGNse2xiHVYHjRXk0VwY54JAgzJza7J6D5ne9Oo0cuPMmhEq2gnzH5bT3XobyIV9ABjkKxsqSMkOrZqLzOyJuK/90W/uYjXu9I2676exHbitexQAu5no+geuYu9LeZHm9YXvQ7XlkAhDrjJIriZMQp2vJE3JoXv6Rio6ul4DahzDjliaUYkNmj82KMJWv4NjX0tRZnfL/1HQehs8E m8uyzRut RlKuN6saI0G/ca7qGzzhJddf8ShTEZFTdRQp/9HHKxaIUotaodkPnKsD3UR9kh/XGjw3VutkMB5LPEPmW+nqnSQ3J1A1etHo+WZk8txPwGdANy69QHGvt/LHPTeC+qaNH4KZikKN4vsdbmHUO7EQQItSWpMNMMMLfjqrIv/x4ajNiu4n02pB1ZgY8Izf6QLJOxlr0G3bNBx6RF/wF9GVF/HBRi4S6ZFPu86K6TGwZXNmNra9WH7/4ddS14ol2pgXswg927HUpcfZEQZLiCgTxt0I60agA8YZzZcsvLrEZC3XYEtrs2XD0rZxju/xW2FY19w/zaOPspLaKg0yfuGXWGRQi1Pl1jzBxrAmncaGmwmUZLFynRKcRHhHg0Ht9WDtsNbxBNGuQWhcb4U42ePdOr6RBTktqLneSjmE1SYBGBFUU6imj4Edq4WRmmW/RUiQZ/DCQTFsqnuTZzqOMkRrfwmttxdvtowjjmeMtPaBjyLCho9oSBNCNX7JIV1aJTzZsJwfJ 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 Fri Sep 22 11:30:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395604 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 044B0CD4F5E for ; Fri, 22 Sep 2023 11:31:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E47AD6B02B1; Fri, 22 Sep 2023 07:31:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF7FB6B02B2; Fri, 22 Sep 2023 07:31:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C22826B02B3; Fri, 22 Sep 2023 07:31:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A7D346B02B1 for ; Fri, 22 Sep 2023 07:31:05 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 86EDEB3A60 for ; Fri, 22 Sep 2023 11:31:05 +0000 (UTC) X-FDA: 81264016890.13.92391E0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id D1B6440028 for ; Fri, 22 Sep 2023 11:31:03 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Z9NWbWz2; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.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=1695382263; 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=CVEbGW4BLJF1l/4uNaMtMi83HInwhhC15AgRCPKnf+k=; b=k7xPAOLliHCEC5QAoUSS4FAYCr7inQ+tWUXn2+7ixO1+h0/NbanNjU0uGlTCKOsf8gbdQi plbY3CozjeHN32v+J6gtr8YiIWuLzmTrzqXwexzLAAoDVb8c4djM5cTFxrf0Tp1ScnIUit YiBjOxZVvb0njOs0VA1myNVbqNvjh+4= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Z9NWbWz2; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.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=1695382263; a=rsa-sha256; cv=none; b=ABF30MYsA8ubfRB9CcSpV72SgKBwK3/WYhGz1DPr/o6I1Jbnj7QcADe8dY0ozoggadFstC M+ad3Hl1ow2tMirEDB9RQwqPL7gPV1yOeWrzFnEtCnXZthEq+2HGB9HGO42VTrpnjYK3Bj v5NbsGsMJDl3wBuQWUk7mA9UAXf62Qw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695382263; 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=CVEbGW4BLJF1l/4uNaMtMi83HInwhhC15AgRCPKnf+k=; b=Z9NWbWz2JijvfO3VHVwg2xxOnc0vP9Kg1IPDuCSvL2jwfdQSwnjM1GQr2VN4MppPVarV0f Tw0b4qnFShPF7mOxVKWQr4OKukprvqpZqeQOUQwzCzPs4YCjxZMr5DuSWos9MR5Cv4F8/l EwwKPseBnFQb8F9svZw8HAiu+BnyKlA= 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-338-3grvvCggPbu-u3y6M0hRxA-1; Fri, 22 Sep 2023 07:31:01 -0400 X-MC-Unique: 3grvvCggPbu-u3y6M0hRxA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2AA49803498; Fri, 22 Sep 2023 11:31:00 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 88E1340C2064; Fri, 22 Sep 2023 11:30:56 +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: [PATCH v3 05/10] iov_iter: Create a function to prepare userspace VM for UBUF/IOVEC tests Date: Fri, 22 Sep 2023 12:30:33 +0100 Message-ID: <20230922113038.1135236-6-dhowells@redhat.com> In-Reply-To: <20230922113038.1135236-1-dhowells@redhat.com> References: <20230922113038.1135236-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: D1B6440028 X-Stat-Signature: arwxodeu56k3cqboejdye78qnb55e7nh X-Rspam-User: X-HE-Tag: 1695382263-951285 X-HE-Meta: U2FsdGVkX1+aX3lqXvQXps+WRnwiMwXUHVrUM54ho+yX3vt7aWhHaQY1KEtTl0ouLmnA2lnWSQ1pmwOmvkSUkfHu7bbovPZaP5bFIiIEZUOsyOnCQJyZ2JUmQyERY7kWsA9he+M6MACj7kDxcJwBT/rDgQdjd9rozWdgfcKE8jwLn8tFgb5NYYMrvFi0ftREmBdggBiRKx4bKldyDOAeyX8GAGh60pg2XweArWWFm1fWXBYKSIwHk9/JCksNhpDfsAh3ZoR+YByhzD0Ax6zn7vjAAl8AfKtVdXyV7bgNk95JXnZEOOW4ztLgbcX1beA+JdASYNS+BiFNcRa+ZxLpH+tLe5X4AWtV9VYNtM7izrd7odRnTQZxySU6my2+vtEgoTBhPqsetpJGjENCKXMC6JO3OCpJ+j20CgmYh3eTIbTZcBJqaJLYnBanXyP3VnizkR04g1VF4OWPzp3F+a+Imhy/8kCxCgjNi91RuGEpWE6f+hUy3hcOS0UahDxK+Y0zyAelt/Jv+O2vjKWMdXDMvzlb5mVQk74IbMIEYx6Z3baROLIjocqpelJa55yIbXMV6rpIRfQ3FsntgkiDrPCNYpdCUOJ14QgKfXJBQX/r7n9f8lKISqI7wN2JUAoHFMCXd7DPSzJqbGwtKYRSyUCt+Q+np2GwYCyQgU6663+3sXp3cLnFd8u7poPAu14heC6VW8+zdEKobtJA6N3+i1JYb2LWCzIjmJa5RZ5aRj8KM3WIyacf68wfHSEUFQt3E/dQONM2heJWjh9yCS2Z1vLwqHFKFRub4Xv8OHF/mP1YnyIzETIdx8qA0z5F55xZG3Kuf7eiunf5s9n/yz7aV0LJz7E17209SW1so3GlgNvzmrzK37DvCy9qXfcm4OntNWKJ1+UWvDn5m3taFYi0Li0PsIsGQ3eQd1rpttG5UGoIzgq9I93R1AzeWcd3yQU8qj7jUXRtdWWU1jkOecEosIY 2IdycYnI qRvh4SXJC3FPwBVl3yFGtksZdlCMXGJQRlUypldSB0zrYwYiVnBWtcEXWG0Yhc7W3McuuoAcs3TFuU1KctuYSjuB5Be9s2/TIdpTGLLrTvEy3bTwk0+Gqfti5mn9Pl8PnI3jteVDzcBcADgE5YNwN1GrQoX04ZacSOWEsqoIA+6WPT1s0sNDPTab0BN3mEgP5Ls1f4d83Z3ZC52fRkdK+27wvP/smJ3jAscHbYw2e4GnCyIxq7HGPGw9aCrosBOzCAkAPYUhoeJNM3oxYYb5l/bRWoEf5nZsp0UvnhWmKiUYhSby4TE0yoXg7rcGf+6qOaYK3JPt+S1s4lSrmxI/t33s+1X1gTITKkuvvlR9dutfxvcL6CBsYJagqyxmR0VHXt+LFVSsepUW6Bm6kwLfSXbuKhlCU1ziYGUhMmrAmsQ2RaVHQBfQ+jmtv80X4J/IYiv2xUPLZvE7TQjaeECvOcVgLTEp8mtvhPschX3DDvmKAhBDNh8+lhwIe4AgLBoidEQkVXuMxN3QeRoANUy4EkS5rxMoQkAwyvnJAtSCl6dID9UlDTOrr4P1LB1AyyoJUsNIgdwj/TfXjqQdCZh3SZgWdUR2H940Jdeau01quMUpt/NemE6tuOkvWYi59g5kYy2JlQ7my1eTBhkHbpPxWCeZR/SJL9tQsqprxOa1vtprym26pAEVBCs+IpwO9rlJ2pZEpa9X5Q5WvGkI6wT3QyUtSmw== 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/s390/kernel/vdso.c | 1 + fs/anon_inodes.c | 1 + kernel/fork.c | 2 + lib/kunit_iov_iter.c | 143 ++++++++++++++++++++++++++++++++++++++++ mm/mmap.c | 1 + mm/util.c | 3 + 6 files changed, 151 insertions(+) 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..63e4dd1e7c1b 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -10,6 +10,13 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -68,6 +75,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 +172,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 Fri Sep 22 11:30:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395605 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 2B13CCD4F49 for ; Fri, 22 Sep 2023 11:31:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC6676B02B4; Fri, 22 Sep 2023 07:31:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A28286B02B5; Fri, 22 Sep 2023 07:31:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C6F86B02B6; Fri, 22 Sep 2023 07:31:10 -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 78B7A6B02B4 for ; Fri, 22 Sep 2023 07:31:10 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4D9BD1A0576 for ; Fri, 22 Sep 2023 11:31:10 +0000 (UTC) X-FDA: 81264017100.11.9DBE7D1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 8FAA9C0016 for ; Fri, 22 Sep 2023 11:31:08 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cywr++dw; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.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=1695382268; 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=rwCPpplnarkjsvZJB79Uk8vm91RohI86seZogpCcfg4=; b=5HZ+fqcmOD2ePFXf89rdFZlh0412TEraNg1jowIUGPMSxwMju2DYj2EETgJWSiTehMqJVU 2wLiBHJNTUrGi9THZlEWbyHPrUJDBAy2OvR8GvfGowC17bEtphRbzhFVMstLz0+yE994fi rLjIAvufjD+SQULlRyiS/5WGrsz6+5o= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cywr++dw; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.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=1695382268; a=rsa-sha256; cv=none; b=sqmLCjcFoNlvxvF8ZHN1bh0vjaIUO8GvWaaGEn0ll5bA/v4d01biI1U1yBiJqznaRof6YF vaxas21moz/Po13C/5CjYPo49pVN8jfANPExZfmejU2Yvw+bdLhGnDUM4PvpoPFmfv0+wk Utoef4qh4rviZDkr6MI7rH1H/4kXe7U= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695382267; 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=rwCPpplnarkjsvZJB79Uk8vm91RohI86seZogpCcfg4=; b=cywr++dwfOCSv9mJtgvlx1CWedwWrszi3k2B+hSLf6RPyTILzmPZWmw6VJcwMOWvDIfcwM /jByV2e5vynQ7GsKjMZjOxNLR05/+vPA8SUihb0W92Vg1rwDG9LYig82tT4HJFltWLurZ4 0UdItA1zHJHuYVYdNilmY37EGxsYSBs= 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-191-I6kTDZpRN0-BY_5qOIe4iw-1; Fri, 22 Sep 2023 07:31:04 -0400 X-MC-Unique: I6kTDZpRN0-BY_5qOIe4iw-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 7EB65185A790; Fri, 22 Sep 2023 11:31:03 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16FF3492C37; Fri, 22 Sep 2023 11:31:00 +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: [PATCH v3 06/10] iov_iter: Add copy kunit tests for ITER_UBUF and ITER_IOVEC Date: Fri, 22 Sep 2023 12:30:34 +0100 Message-ID: <20230922113038.1135236-7-dhowells@redhat.com> In-Reply-To: <20230922113038.1135236-1-dhowells@redhat.com> References: <20230922113038.1135236-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspam-User: X-Stat-Signature: sugcsgy9s93wcxs58wppdhs7gt3ghyk6 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8FAA9C0016 X-HE-Tag: 1695382268-434830 X-HE-Meta: U2FsdGVkX19596OMb36zGOUeF+rMNNwZSvyqfb0b2khfPGxI5G07dRYURPVFGuv1DYGVkMR4YjoGvLvnh1c0FrggE2aPfJ1oZG0U730V8ypFfzZ3a80I2QXJNjf8Zf778dfzoNc+tTcLpl5ca8NTz1P2zKJh3cqsZ/8/o2ijyKC8OwboKaGsw40IkTWLN8dbOHJKvtjxBJHeVNlSR3ZpY2fvv6aLx/IoL3bqeaSIY8xcAhOYt3ULBiNQ2CopjEKe8yl0lUb+qn+bE/EqOHWfuOk+7UwUTxcG3HZ5iIPcOnyo0BDUZ5p0IKlz41cEm0oZ0e4L0cUgS2/TwrHY6KQwU90C0BJCB76TjF2jmllx6wppBhs0K97aZUSPhtGK8ci1lxXgImfpWyssyEHj61qsDcK+z0e2hQrgacD+jf7kt8KpKiDnIT7COBldc/GSf94QB5S4ZmAHj4a7oJrUloT8np5S3MzdxcvavwJV3vwxvH6k0vz6ALam2pmg3jIvOAyQZp6kkbLlFbBdLSRrNLl2rseQvFnyqfHIe/8a1WejYNI4jf1VJqws67L9sByBsGRKlviAkeeKwcqbbYeYmCkoyTfdv4MwBz44/rqXYRq1ijLtVVrMBA4sDbOiTC5s8AReq7JqI8VbUxKlp2ntbLS7jd9eIsnXaqovy4RQV4XMDuJMhIs0BZyvIVW/r22pDWLJksWwkTBMpiRIzGwb2Y/vdzFQa5bjuLL/zaAyxIXYX+hji9mDHsIMVNLMFwxzjnE9ML9bGk2V/7Q+rWmjE1Ju8adUjsZJHxlq1C5FgAzRRAxD00cQ18OkoExzP6iwtwZPJozvsChClZgn5KWpp6ZnnhdpC42oFHGnj3hEtnG3Ah0a7OmTb+f5tgCV3o4sCRf6Zk6aKFfC6HfgpfSq2raEW2eOehdaw3JXLbTyf4/Cfvk1QGztrofhvFUnl48v5PrsEdvSF0hOllIfb3JTzE+ X9EXk2xS 2SAqMZr2mHAnNHMN8HVgBCnL8NaJ5J/nHIttB7eQbnASu2fhzWTRZ8z9+qMNg+pFOJ46yP2s0iyfmqsaNC1los71ZW1dPRvgTQUXyhVcURdt0xc0YO6F4ZpLQc3UIAXfyZ1nP/+6q0SNxKgC4dB/OdNNq1cQ3JvG0Gl1J+1rN/vVOSC3C6CyZehiE5D3Qrm5JVSrzEPE9aCmA7OYq2apEfAbobMT7JPR6ksgvcM0sfFT11/hOQfs/XohioNBKkd0v70WouQTRZo9ZPGxZJriy2PcnaLEoqd8AMDOBA7FcOySDN+X1sHUQcdc8lIn7m9iIsxUnAuv6P2gJPQdmL1umxBvqLfB+cnhQbHGm4J+JxOENKr3GAN0FYJiieJMHCaWjvMkVw2WqqvjErXYzXKQkf/n3ZO7k7RrsdJL2KsunEsDtNddcugqnfmE2pByLSZ5s28SgM4MHCCy/UXjjFml9sA3Ohy1mjFQFSUsEWqR6DVksPR02yekKBwvd9wZukt1VPkKOZTXPiH4EaRv4GsUjESYqYqSK8a4ZXiqwRik5g8P9CIDvLV6DdlhFVmi2aWhoDc1FMe1CFV5n9BpD2zimysu2aQa1FjKGNw2G6B+1w4+f4rebOneBT5sWpw== 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 63e4dd1e7c1b..34f0d82674ee 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -117,6 +117,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*). @@ -172,6 +189,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, }; @@ -294,6 +330,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, @@ -869,6 +1101,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 Fri Sep 22 11:30:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395606 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 4FC2ECD4F5B for ; Fri, 22 Sep 2023 11:31:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD0F26B02B6; Fri, 22 Sep 2023 07:31:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D80966B02B7; Fri, 22 Sep 2023 07:31:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C236F6B02B8; Fri, 22 Sep 2023 07:31:16 -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 ABF366B02B6 for ; Fri, 22 Sep 2023 07:31:16 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 7F64C1CA474 for ; Fri, 22 Sep 2023 11:31:16 +0000 (UTC) X-FDA: 81264017352.26.B552F12 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf24.hostedemail.com (Postfix) with ESMTP id A190118002F for ; Fri, 22 Sep 2023 11:31:14 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EyGgZ7ke; spf=pass (imf24.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695382274; 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=zNOJj+YS6mMGjsLK5S7tjKltIfgKSXCOHuT8F0vbcKQ=; b=NV/OhmC1YpinpM8St58wm9AJAjzULqYBmG9/qI9PW6jz+zd/gzQt6s+r/JI+IRbeNTERUK iy9sw4ciZUpJAz1tysBrua99sBT3OCvd0PzGGC4z9nTUo4flIuW+HAxMOiTXS18BnegGtC baGvADBDVSpyutmFhAPGl/l+c9U5z5M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695382274; a=rsa-sha256; cv=none; b=zf7FrxvxehVA2qtxx9xpMLGlPq0cnBHTA7mrEIEEBHkU3taUIr4Kq7RPuwb0Pr7R7Uasba WxKG3Yee2yE3vgTgkorUwTHwbPAU5ehXLnVztbjU80WyCl3Hv7KQL+mYGLfHDUGtNjisZr HQ7udqIJdM8Ax8z/PjiEPwzROST2x+Y= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EyGgZ7ke; spf=pass (imf24.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695382274; 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=zNOJj+YS6mMGjsLK5S7tjKltIfgKSXCOHuT8F0vbcKQ=; b=EyGgZ7keEBvOkOc2h8XCzS5No0/Gs8LHoy7fkS0apRk8CXjfzWO7g4VxIfOEANUk/nK7eB LnTOOp4faFFMDkLa+Xp67M0U4Oey5syvk0cC1wAoGO1a9U1JjfOtEa5QqOD+6vOH124RD6 8dP5jZ/pPq1ugPzsEO9K+KET1LdGazs= 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-332-iRzbud54N86XWStzDB8ZjQ-1; Fri, 22 Sep 2023 07:31:07 -0400 X-MC-Unique: iRzbud54N86XWStzDB8ZjQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7E87D38125AA; Fri, 22 Sep 2023 11:31:06 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E8CE1005B96; Fri, 22 Sep 2023 11:31: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: [PATCH v3 07/10] iov_iter: Add extract kunit tests for ITER_UBUF and ITER_IOVEC Date: Fri, 22 Sep 2023 12:30:35 +0100 Message-ID: <20230922113038.1135236-8-dhowells@redhat.com> In-Reply-To: <20230922113038.1135236-1-dhowells@redhat.com> References: <20230922113038.1135236-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspamd-Queue-Id: A190118002F X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: yyszhtsinh18eucyjf8sa9ghzat3fk16 X-HE-Tag: 1695382274-6314 X-HE-Meta: U2FsdGVkX19TxxXYfE8xoZMcZoO/u8W3LKn5xBLwMVn8uMuJ9lSoD964agNNZ3IFGdYBeVJUQ4TKo2eTAAdQqD0zmmD2rvVVLoAKQWvu3PZhRcjixenaQwQOadwZsMMSKYWMloFr+xr9Fr/T+D+xmHCr0/VzPxZ+t8FrnxfDMNJW5//3mLdyTOE95avv2QEJzalnq+xzxrfdaHeUSlJDlKttA4OIj/yvO2mh9/a538gTE2oQmZyT6YZGZtcquoxoUEX7SykgUaT4VXoSklnsS3TE82dlYLOmajHCVLYQVJtoFgj1i3QLc2vZ9GtxY4LdM+kdHQd4YEav07wiY8D3CKS3iW9h9+X93YhmTjGHURPjaFs4tojCTOzYV09ZIljoJxMG1tm6CmpXhFA4sukujAUZDnf8v6pxlwdxFXQXnpMTgDnMTc4kqu6mt0CvY7zNaRj8CtCXedwmudHgR/z6IEUTR3ggcZEfSrl4eMFp424LPzHg4cwJnGG4+IkbmXGeNBAdi3o2ct/rC7ouo7NYXr4BoYbePoKQfcr7aP2LBAF2qZDP5irJXfFL2iM6A0bxAyRZkd7mmPFZo2KoP3w/L75Wqor3vL5SoJOAZioS3IHnmslSHCXSFz9SgxRnIBQSaZNzZAdPfPLLeRoAsusIfA7jt/Tjz1g3qldPvjQmnYI5eM1PjIpL9msSQrD0sQiPN6lzoK+Owxt21OrtriMhm/gzDUaKmVv4tp9apNWuGnPrJWCx5sbdque7VDJj0+14CN+1BTWKEwnHQ+Gbs5HWui7UxFQvA1ONs6JYtAroQZRGn66unPwK0n3ILAdGHWFb46OHsZE5V168bx2SkvnCc4tRi8gqoGau0PuNjnHjYoIDwy5kEng1/6NNsvcEtVkdxIIFr0Y1JQxSAjwRUG/X2rH2TpQPkaQygdne18pIPu7roXZsWbUvC+TPbA5UR/g+qOMFFUdlvr3ort3lf4A ePfLlYp0 m2It5QoyQzJ9tZLJO6KBd86FbAWSXF5FGUu+O6wL2748iuvzAHo5ylyzjXroO+809L3r320pXdSwqysAMUsyUv9zIw2gNYJOKk/HWopBraxrRH8eKsi8vdBKAGrUTtCumEFllnoCdx7VuaSExI1esr6G2CBUV3WhuYtxIp+z23JChw6VvTGQemjnJZG/ytXMPzaWXxTVUBUJoIKjFlf7Yd1fwXEArUZVPr/BwASrtBILDTdiJkJoDzh8i0W2U6rr7SjWahJ+fVjTbVLALbmsaOlIv+jrZgmBmmYJo3iCAp7kcO+LNu15NCEl4zsKGA843XLDIcS9FrrLd6m0+pOpxgx+xva7czsgvjZPPNVvYHFf4/bWvjFKGYdE3i/f+fY5q8zouoNc0XRKpCpEnpbD+IoFGq2BtDboExPz9NKFCxdfMoHruZK/IYlsbd8vynUYMnxFK4WTzWL0y7DW/iKk8LlA5SVuCdz3DPXQ0EXHPu6UXdSbbDq/aQ+fBzzdR8UDTsOcS6rmNLS0pAvioMwzjlnpxvOiA4ElpUvPzW5beD5FXFc0fmTnXZ4ozXoFZzvdkS044RN777whTqwBMov4kPfIfb57g7FYxYGZ0xm0s7I2EUx3CRzr0fu9Acw== 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 34f0d82674ee..fdf598e49c0b 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -863,6 +863,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. */ @@ -1111,6 +1273,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 Fri Sep 22 11:30:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395607 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 ADF9ACD4F49 for ; Fri, 22 Sep 2023 11:31:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AEB7C6B02B7; Fri, 22 Sep 2023 07:31:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A9B926B02B8; Fri, 22 Sep 2023 07:31:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C9306B02B9; Fri, 22 Sep 2023 07:31:17 -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 7606E6B02B7 for ; Fri, 22 Sep 2023 07:31:17 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 36AC3C10DC for ; Fri, 22 Sep 2023 11:31:17 +0000 (UTC) X-FDA: 81264017394.14.070FB80 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 7C9851C0014 for ; Fri, 22 Sep 2023 11:31:15 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Dc8gP70f; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.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=1695382275; 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=SHVN5dprl5SXzKPIzGJgk8i0Q8IZLJJ1is7dtiWAZyQ=; b=ocWbTyi8xKc+WzLlL77n3jZtJUdSyG6T2gH7W/ho+s9xyBBh8l6LAEPY6zYvjCaeuxnHmD 5KBCw2cpE4W/uigu/G/KYw/TNNAkfC70xkh7r4EzbU4RePnLxM+xg+l8tAzgqqcNsYtTQV +Di6OpiJ0ufnqkqtmBizR/Z8yZzB+NE= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Dc8gP70f; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.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=1695382275; a=rsa-sha256; cv=none; b=d1Spk3hEzZYCNdQDo6g/eVjjkLeuxZdZj2buhKxA3QqhhozPrpzQ2j/ZuL60zpjzqablXv oPADApHIipyJCfR0F8hTBHmCIwgi29tYpf+ACwSr2lIEmdrlYtS9RvEclnmmFtxe6hrnDa i++lkfJd+R/coUA4+c4jgTpJzciuGd4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695382274; 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=SHVN5dprl5SXzKPIzGJgk8i0Q8IZLJJ1is7dtiWAZyQ=; b=Dc8gP70fw+PpY0LFzkjFPpUKXiBnqQC4c1NIhzMOIWINr6XGN5iOJdqyG5faKx+tqGNfUg iMnKy/w4w805gpzHHZZDJuTJizV+wQVAdr58+JsGnsGuslFnr8JYzMT/FfQrtutOQuRr7Q harjG0I7qxVxiQrf1vueL9AejD1jhyQ= 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-487-T_FPJATDP5C2zR1rQTrR3g-1; Fri, 22 Sep 2023 07:31:10 -0400 X-MC-Unique: T_FPJATDP5C2zR1rQTrR3g-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 77D47811E7D; Fri, 22 Sep 2023 11:31:09 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3738940C6EBF; Fri, 22 Sep 2023 11:31: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, Christian Brauner , David Hildenbrand , John Hubbard Subject: [PATCH v3 08/10] iov_iter: Add benchmarking kunit tests Date: Fri, 22 Sep 2023 12:30:36 +0100 Message-ID: <20230922113038.1135236-9-dhowells@redhat.com> In-Reply-To: <20230922113038.1135236-1-dhowells@redhat.com> References: <20230922113038.1135236-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 7C9851C0014 X-Stat-Signature: 1q6hcqzrqe4qxqzno39d6mymzk6ceomx X-Rspam-User: X-HE-Tag: 1695382275-823566 X-HE-Meta: U2FsdGVkX1+B+yfz2YIj46mQcyd3Dzdn6i6nFsSi1uB21jP3EfFxa9VK5O6Y26pdmeGHfXhBl3wPYWCj1vouiZFIABVJGfyDPooJyjdjq4S7opbQkpHsJ89mve69UGRP3juHtPvn9EUW7h/RADWv2bB79/Tt9sqb03aOCWpOZNksifsDew/1OtyewWoIEsuDrHIiG8c9wC5K6SDtXd8NJNWf6qPUDDlZ+EHtWYpCFdDWYprbG1kf5DvnjN2PpRMBRLwDrUNe3X9JxEJpoguTP2SzJj0QfwmPiLyA98COUPMAlzApJar/KzsU+kJCWqco3Ic+vskLtVkmXjV6MWuXP6QwQ2tSd/QX6+H3U6njYrW1AqpuCNbndHVbH3Qrp2oOymuwwlxlDTEQDW9bzsr11L49Mc2KIaQOEzZB6eaS47jczd5pcLtMFu9LSSuDzmfwfS2fSQTMCHmDpWduC95HML8O7MEAUyRytybF2F3MgIIj7rJ1HAQmLbPnmOpX4GU3UYMjKIVTfcGyCtXItaTWda27rLmXG3QpZtFKw62+PF82UAY0tesd3XsXgjxY/Y8MpwcoQbNEtfX8/6PTxESAcPKAPOIxQtx/PJRdC/qdwKTtx8O78trmdGNGbbrsC0AEcedHKPdcZSITpp58wGzN8HRc+ZRw+raHJhp1QecvjYKTXvVPkhFg5JHC7AIbp9RNQA/Eij4B9hFYKfISeksLVi2u6UApSr79woE031tuJ3k3FzgTnfMmJmWArY0VnWV5DrBBpLlP4rARjC9t+T3sdowJmueja02hCaNA7z2GuHcWv9Ez32l3rpvB428rngLDzherODHsQcq+LJid6hwLMPeeHnQ2rlnnQtWCNO+aNn6u17MyVhcvlN0u6hT+R26xlIhgbju3CGa0C/RBT/va02NG/dD9easDdRPjDblEj4yyoMQPhXA1Ks3RkqV+4XB64yAuH8tQDvtrIhqC38H +w6uUdUF YO4rniHnvk6R5rS3wDSVUgDwuVGbe7/EuxaEC5AEoDTnqOlBhoiKN1c/fwasLuQEqNHndireVgZjbmUHEtxovAcTcDBnLGtAYJgRpUwnzQGvkGmVERz5lOXhPoPTH7bC8v6usP6UPMn1TxRJYXl+nzkDbCzoX6O7Pn0YL+2CtfxpG3uhhnX3laAscINONYup3bj1bHCfw+WMwHrGc64youj6roYeORWxj6s/8o4/fllzY4wH4szeZFlNiCMaviH5s9o8k4XwrXHvblbEhg26WChHseKUKb4D6VfgMkJ6CRUiQ+p+3rrz4pgjbBDA+LiZdFWEoUjCJyIN5tT9UNURC5Xg8lMLgcQkOC0A/c/emPvZGvuHqOq2EN0vcI9bZ7CeGpWSKEO1ik1DB0v+3WESq0qG31Flh82Amb3S1RD30Fqv0p7lU4RZnnrKX1BqvnP4CZywGTkqHsgoIsYCj0R09I/an0FIr5zy5Zp8GYjCkOsL8FqwHlQodpf8mY5SzZb3zhO8G 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 fdf598e49c0b..1a43e9518a63 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -1262,6 +1262,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), @@ -1278,6 +1525,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 Fri Sep 22 11:30:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395608 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 B10A7CD4F49 for ; Fri, 22 Sep 2023 11:31:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 489656B02B9; Fri, 22 Sep 2023 07:31:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 434DC6B02BA; Fri, 22 Sep 2023 07:31:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D5516B02BC; Fri, 22 Sep 2023 07:31:22 -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 152626B02B9 for ; Fri, 22 Sep 2023 07:31:22 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E2A2241087 for ; Fri, 22 Sep 2023 11:31:21 +0000 (UTC) X-FDA: 81264017562.16.5CECCCA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 33DD6160004 for ; Fri, 22 Sep 2023 11:31:20 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ec2vwQGJ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.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=1695382280; 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=ccEdlostLZ9hW/Y+0NbfOfNDQJd+s3hdO6ELIs/CNv4=; b=3y1+QXSyx/fYqnxVDNKGDj+b+lNXaN6Kp95Qa3vGnlnHGzUElQpC6xjkCOrAW+jC3uVHhh cuSEvwKtMwaXqf+IhhWYyOiG4mAVr+/jQHnhSYqxYSOVBvc6BKJ6eVaRAX1JT8HK1GSum5 37HrCZo+8ej6YnbR4B8oSj63ExnO41g= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ec2vwQGJ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.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=1695382280; a=rsa-sha256; cv=none; b=het7aE7k9j/hqwE+KTmyS4rv7ghb6F8lFWaDVWdjNjnqkHu1F+an/eyE76SoApQUAZ9tdh yITln7c5blQQkAsVu1j2czjv8Si7Ag7DZFz6HRkpZ/cTn6DVN2x36bf1jsxDeYPf54bnfp D41wXEJTq0u6s5ICTZqoCiL4eVdCBy0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695382279; 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=ccEdlostLZ9hW/Y+0NbfOfNDQJd+s3hdO6ELIs/CNv4=; b=Ec2vwQGJrhcedGKuXMrb4ZxFw+K015WW1v4r3pVBNZ2kxKmA5YnlNJ78WOSMCHCI2iwR/K RFPYdr3VcO4Co67U+2vrdTAB4gWYNNQVltUHqXPACxfv1Ey2YlFVFwaUCJeMCiwbZY00G/ W6H/DuDdobphFmK+Prz0XS9k4o97juo= 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-10-gL529IiFPli31fOxi3rVow-1; Fri, 22 Sep 2023 07:31:13 -0400 X-MC-Unique: gL529IiFPli31fOxi3rVow-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 55A34101A529; Fri, 22 Sep 2023 11:31:12 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 161112156701; Fri, 22 Sep 2023 11:31:09 +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: [PATCH v3 09/10] iov_iter: Add kunit to benchmark decanting of xarray to bvec Date: Fri, 22 Sep 2023 12:30:37 +0100 Message-ID: <20230922113038.1135236-10-dhowells@redhat.com> In-Reply-To: <20230922113038.1135236-1-dhowells@redhat.com> References: <20230922113038.1135236-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspamd-Queue-Id: 33DD6160004 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: cwxdgxqwctk5ek87dw7m5aiwmbatj5kg X-HE-Tag: 1695382280-454660 X-HE-Meta: U2FsdGVkX1/jvMiQZhG7j27dmbJYmlns8youKReKGiE9tXSmR/46YiiQtITBH2eMbFq2x2bdCC45nHri5LDpN8zA4YieL0WFaGcYF465N3jb2ULkXSitbYbRGJtRPhpFoLwKX3+ZF9Z5d+KpSi0zFmX0/G/hmGo8ppWPccDk/VatIBaiYxw+r592PENUupDAP2ZhFykIdzgNMoazguW4Cqjp2Terx3LnpWFAk6BfzImqOpdKUjXcCVDhtv2JUzUfDdC1lmoWhKH/XvgFMlCM+COI1ZsjB797vJUszeFv9P6GhaaoPpnxr8JquVG6f/mLXNTXTEzii9hLHxwlgChPzgJkDqcgBuMwpW9Q6DG1R1zd2CbC+uYRxUIA97rrpqBIiwwxrXo6HeJWpqDm0w6VvwuRnxdxAnm7EuiH9KZDP+ePOcPd3KKrvxUFkgEblGpX/3oe1N1GuF7kycxClvq4hE/Yi8+yYH+YCkurhad3cAxaPfWUvA+R0Iu6RjjN4NeYoDY1lpH3i9XwRCfuxLsByY0WhH6JJFSZZdLwduQ1Ep5tZMlOWB5e2E/uP9a60riT5bgFExH4KdiKkOZ+EL9EZTTwLIa8jsHsLjlBIhrCM9LLjsa8kOqm8u5MSgMlz0xOEixmvDn0oUj/805HxfGfgeR7K8pw8kZbUmGY7xIhRPB/Kl4Ps1yAuLng7glSj/z17TGPruJHljDgW3rV+ueqyPpJpeRNLBy1u5dK05IfLSgaE2arvJbn+d3XMK+jJm6kz3Lto5SMCChtfW3nP1ZqkySK7qpHa40rGIDSNYUHFUYR5xfOOywFKgZrX3/3GW9Iq7Lm8IkuRIYJI0sv5rrH8duIGj6cAMjcYnE7BTMDa4dPa8QMxcLnsFYzmi0PY5SJDfyLENrlJ0hblZ4Ucr6P9omdNiSvwa8JXOtOqo6pJdKN0ZbcYEIzTv+XsbKo86Z3iEGdd6p05zdQ8gqZ/I3 NSC6oWx1 jGqIzumg+4lk3zDauUqACRVB11sEpxt1UTDUtjjA4sfI4rWcPQXMzXsixM7/HYcwkitMD/Qjlrwq6ONQlPIOgql6EdchH4n6oo6jWs01opZsFCgh4rMnRh/6Uixq9qin9YCtbCbCK2Urdl+h2fnsf9dWwCbUdytCOBLS2RpUtpg3aZ2lqNZAkXc9xWdljTrPyhyYw14dOKIxfQDsG41IwrZSDmG+ddxLj7TVvSxbxsTLxTUV6vw26LimlwAOmQkxcOJ6ZyBeUPlHe5ZMcuh9P/uIxMBSvVvEJUkyCzEgyjyoxa5IVgJU4vVwZLPjq4Xw3h21RZgmq5iMZTlTffba5hXU4dA8Ioqz4n9TOR4kQiLNy5amoi0KWYVCqUJleRDY4l+iA/1aYCoLG/8RKYrw85riVKkItYDLYgbCo6+rUwSh8+H5C70Mt/FWZxF45VDCX/NEvG6bnqHNfegMUZSVJDMl3/EOWR3w54Mcwuk6Cv8n/gD8BYlIQBjEftiygiBjeFeG8 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 a kunit test to benchmark an xarray containing 256MiB of data getting decanted into 256-page BVEC iterators that get copied from - modelling bufferage being drawn from the pagecache and batched up for I/O. 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 | 87 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/lib/kunit_iov_iter.c b/lib/kunit_iov_iter.c index 1a43e9518a63..2fbe6f2afb26 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -1509,6 +1509,92 @@ static void __init iov_kunit_benchmark_xarray(struct kunit *test) KUNIT_SUCCEED(); } +/* + * Time copying 256MiB through an ITER_XARRAY, decanting it to ITER_BVECs. + */ +static void __init iov_kunit_benchmark_xarray_to_bvec(struct kunit *test) +{ + struct iov_iter xiter; + 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 BVECs decanted from an XARRAY:\n"); + for (i = 0; i < IOV_KUNIT_NR_SAMPLES; i++) { + size = 256 * 1024 * 1024; + iov_iter_xarray(&xiter, ITER_SOURCE, xarray, 0, size); + a = ktime_get_real(); + + do { + struct iov_iter biter; + struct bio_vec *bvec; + struct page **pages; + size_t req, part, offset0, got; + int j; + + npages = 256; + req = 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); + + pages = (void *)bvec + array_size(npages, sizeof(bvec[0])) - + array_size(npages, sizeof(*pages)); + + part = iov_iter_extract_pages(&xiter, &pages, req, + npages, 0, &offset0); + KUNIT_EXPECT_NE(test, part, 0); + KUNIT_EXPECT_GT(test, part, 0); + + j = 0; + got = part; + do { + size_t chunk = min_t(size_t, got, PAGE_SIZE - offset0); + + bvec_set_page(&bvec[j++], page, chunk, offset0); + offset0 = 0; + got -= chunk; + } while (got > 0); + + iov_iter_bvec(&biter, ITER_SOURCE, bvec, j, part); + copied = copy_from_iter(scratch, part, &biter); + KUNIT_EXPECT_EQ(test, copied, part); + size -= copied; + if (test->status == KUNIT_FAILURE) + break; + } while (size > 0); + + b = ktime_get_real(); + samples[i] = ktime_to_us(ktime_sub(b, a)); + if (test->status == KUNIT_FAILURE) + break; + } + + 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), @@ -1529,6 +1615,7 @@ static struct kunit_case __refdata iov_kunit_cases[] = { KUNIT_CASE(iov_kunit_benchmark_bvec), KUNIT_CASE(iov_kunit_benchmark_bvec_split), KUNIT_CASE(iov_kunit_benchmark_xarray), + KUNIT_CASE(iov_kunit_benchmark_xarray_to_bvec), {} }; From patchwork Fri Sep 22 11:30:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395609 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 3628FCD4F5B for ; Fri, 22 Sep 2023 11:31:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB0D66B02BA; Fri, 22 Sep 2023 07:31:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B60D86B02BC; Fri, 22 Sep 2023 07:31:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A270A6B02BD; Fri, 22 Sep 2023 07:31:24 -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 8D4636B02BA for ; Fri, 22 Sep 2023 07:31:24 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6750B1A0FE2 for ; Fri, 22 Sep 2023 11:31:24 +0000 (UTC) X-FDA: 81264017688.19.2554046 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf10.hostedemail.com (Postfix) with ESMTP id B2871C0020 for ; Fri, 22 Sep 2023 11:31:22 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YlmKNV0s; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf10.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=1695382282; 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=YZNprSzbt9e8k58JcxEUqpXJf2zPy5yDQe5/rD+YGMw=; b=4voXqOjAEV8KBcSYixuZADD7Ak/oFuh1jV7zB+bPo0XkmEA10p07lGVUl6em7U+icWbI5a ozeEbFb9spaq/yRzKaW5kLe2Hd9d52geTx/+NFjkZDVXMlJpPf5V7pFTVvJj981Ee9IwKW PX7icpuka0JdNs2DMDeStzxwczEthoQ= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YlmKNV0s; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf10.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=1695382282; a=rsa-sha256; cv=none; b=W+FzLkF2FlSjpZPOODlRg6xlN5yh753Yubu/NyKY7tCjEtq97fl02rzdTjxIgAO+26Hz6O IB3sKJc8HVTsFRtFzZglFX1A9vqf4y2EkLrUvXuBY8gIObx0cC7PNyWFmSBPrO5ShgjRs5 yFeMr7acUwg2CfGFPIKXWE5IhVNA5A4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695382282; 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=YZNprSzbt9e8k58JcxEUqpXJf2zPy5yDQe5/rD+YGMw=; b=YlmKNV0s7cnnJA0jWwlz0meN+za8D+vIXzxrrArO8ivTCpzuxek/qrMsqA3yc5xwThjMML 9R0jX8FwLI91LX9LW8nwnttCaC7UJtXoGzGIorN0D5uMgV8a8+V7T+wjXRqaPSLF4yi0c4 N3xlLfClkp3xnc/WbrPVC9+xBgpeUqk= 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-44-75ozITHwPxqfRUZSOFIvLw-1; Fri, 22 Sep 2023 07:31:16 -0400 X-MC-Unique: 75ozITHwPxqfRUZSOFIvLw-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 6EA2B101A529; Fri, 22 Sep 2023 11:31:15 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CD1420268D6; Fri, 22 Sep 2023 11:31:12 +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: [PATCH v3 10/10] iov_iter: Add benchmarking kunit tests for UBUF/IOVEC Date: Fri, 22 Sep 2023 12:30:38 +0100 Message-ID: <20230922113038.1135236-11-dhowells@redhat.com> In-Reply-To: <20230922113038.1135236-1-dhowells@redhat.com> References: <20230922113038.1135236-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspam-User: X-Stat-Signature: u7kur58gnafsys76rzosuaor456ys64k X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B2871C0020 X-HE-Tag: 1695382282-117532 X-HE-Meta: U2FsdGVkX19AJsvKkU1vzkBf8oW6Mq99tZMDVpoPI4poKUUgMIu4ME2iZccPCmXIWKB5/uG2jLWcyyDgd/WalcaxT+cItSqEd1SJ0ZMOBvorjQuahmdsSLRCLSNwjYOuHvXv9QWOcO54WgxF1z0nF7c9CbZ7v2bFnk9VrAGI+VX4Wgi0+rhi1z4LVropmZwSoJ/tQ2mSPRoVGRdXv8iAMv/3QedFOxD7FZlxGegeGVsb7DUPkxMdN532yzLZRaAJ4ybkM4btFFYqpAPQupjO20ll++UjsaTU7EomwQNLVN81RVLOkOv93bfFbVOWmC6dYS4w/oH2VrO1ksAkjtn1S+CJsWCasOqXcT+KNxyWKo5RLKqeRino7BFxoCqLzOVcHSzGl9YaaalH+14XivkGBaOZDnyvvmWG1d5DgLfDpbo/oebfDtXx1d7TgK+xjKMYZbi5tF7VPmJjmcjbP3jXrob1YV6NFjWsPRMhfK7KbZlf03UjNzPTdq2kmkp53LAzx/uMNQVq1L6vCNqGdV3gpfYYdZ8mzbIGt7h/RV47oH/wKKAu0rzOnvS8on8+aKnvxriDLeszbSmUG5Sr3i0vPCjYSQfMAYCabc1th5aSft42mRCCIGJ2d0jRtacs4o3ilduX4hL7+V4LmxG1yTeINywt+mcURvRObpeao0C3cQPH4BNtTJj2CPn5JGHPtpUdj8tp9shYfh0AOpC1ADzq8uw3E2vK8h0yXeaXwEefN9P6Im7NrhHpCI5+kWCjW5/Ky8Sq9G01l896wYYum9qedZYpdgtPCLdQdOOAJV139vAyjrHmP/NX9K6obTw6JKKpJ3lXTuTS/mSMNRHQ6kFCR1rb5aGGvtRgj/yWiugg4ZgQhAh5Inx2kR0oV26Nl072pSvgoZDb4vOxj9bDeE/QQxI/sbNs3Fz9KOn/HkWfSOcBzMhwouiN9o3DjPpfo8iZru3k8v+kF089L2cCpAd aZsG9evc /00LBo2yt4tFVgohF+xWAK1+VpXFTBb0/KQRkwX/ZidhpMVrVvQrqi5v4SYaTMAk3nESZ0CjvLUAHq/vMHO23vXrDWLXJkx1EOpCEOEi9Q+z0lawHez14We1a1It1qJeNm1llgDsrn5JQiCMQoeuXsiHb+b5Vo4G0QDGqv7pURxu82G2wetGRhUWn3cfvoyUizgpVhhKuoLynJxdXP1xttA/lzAm7f0clLWTNrzYHEhmIsTJ8HhvMyed2UJOARJXv8p3Gw+ZVOXho8rwyrJKzwF/1wBekQxSqq0+9YDWROe5gSa9qotpDb/Ros4hipAxk974kSWfmiVc9MX7gt0k1bdyunN2DtmJ5jTkXO7PyXD/PjN6Jb0StuTCrz6EswsKVJotOXplqgd96DqRA3eCzlUHrK7wBafaRKgTObuMno1WKagdV9oDtu1xgpgg2GgMeqRwCTwzI4jP2KzI3UeS+V/tlOZqr/m+4PuhhL63uEJx1SJYvvJUomev/yTWMW6U8m67MfskSushjRC72uWbGK/CTcWFPp0tIS15okDpKCGVKXHm/P9MGw3F2PFIMDkuMIuNN2dJf1qlMzSgxGo8odjnsfGurVPEyhKY1PnULCt3fh6r8VALig8e87A== 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 2fbe6f2afb26..d5b7517f4f47 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -1325,6 +1325,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. */ @@ -1611,6 +1704,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),