From patchwork Wed Nov 15 15:49: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: 13457010 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 47FDAC072A2 for ; Wed, 15 Nov 2023 15:50:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A6FAA8D0006; Wed, 15 Nov 2023 10:50:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F97480018; Wed, 15 Nov 2023 10:50:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 872F08D001A; Wed, 15 Nov 2023 10:50:03 -0500 (EST) 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 6AEC28D0006 for ; Wed, 15 Nov 2023 10:50:03 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 498B2803A7 for ; Wed, 15 Nov 2023 15:50:03 +0000 (UTC) X-FDA: 81460624686.15.5D68645 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 0D7CB180027 for ; Wed, 15 Nov 2023 15:49:59 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MbF9drla; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.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=1700063400; 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=cLLvfQ51lSo+4WMNcgzbGXZDWiR6UxkFGe24CGZyQUFlT1D59lXVJFrShluQXxFaXHbnfi ziJRhG3kWLoz7bIc+3UxBnx++Dkta+YDmW88qk1arL2P0n1GQ+lbqPTOy5L2uWXVbb/gPB ypHr0b/rhA81Vr1huCQ3ntS5x2byhlA= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MbF9drla; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.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=1700063400; a=rsa-sha256; cv=none; b=RVHfyUHg3PJbnSm2kKmGc+UjZP/hOGUw/y2Vhe8nbFR32j4sPk3gEX8rhV3c4vWLaaMAAm ZOji8Kd3S87/Hx1MjGLtvearAwtwXnltStwOEyZaL5j02Vk0IbEqqKTKO+imqY5V0wNcgT 2ewTZP6yvPW9IWgsDYlGjN0+63r7dA8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700063399; 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=MbF9drlacVkfyy2S3Ju7iLyPVi1MfD9QrGfrOxHrBV+aDDbqbvUAeEu8HVa9O3k5qfQeac 6GlKc6aIdoDObBlCCsGn+ZrHB7LIBv9Rhx5V3JNZDz7ZIZ0ZQrWZk1Jo4iLhjTVJUNtw7V 6lw9Gdypg3CiEfuI24FCQ2OtrOR2ZL0= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-230-IlTGLqZBOdmHvz4PCUDiHg-1; Wed, 15 Nov 2023 10:49:58 -0500 X-MC-Unique: IlTGLqZBOdmHvz4PCUDiHg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D97E13C000B4; Wed, 15 Nov 2023 15:49:56 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FED7492BE0; Wed, 15 Nov 2023 15:49:54 +0000 (UTC) From: David Howells To: Christian Brauner Cc: David Howells , Jens Axboe , Al Viro , Linus Torvalds , Christoph Hellwig , 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: Wed, 15 Nov 2023 15:49:37 +0000 Message-ID: <20231115154946.3933808-2-dhowells@redhat.com> In-Reply-To: <20231115154946.3933808-1-dhowells@redhat.com> References: <20231115154946.3933808-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Rspamd-Queue-Id: 0D7CB180027 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: dxibfbhs4jsnaa1k4r3wpp3qkatz98ma X-HE-Tag: 1700063399-770072 X-HE-Meta: U2FsdGVkX18TEEhOFM2+fm8N3+5nHP+mUTCxQex+EgeLV3/p1GOTMHmXItsK8zbzYq+x5V3MZqzuN20M2+DtJbG5WwiMwweHbytQQzToQU8EhGi3s18AG9Inlyr4hEIXIWOP7D9+cTVLd6x5pP4LCDIz5bWIcwtNoieIzyp6xebpcH5kYxiof+mcPlmj158tfXq39a+XCzlLGU+EeLl6rjSRIPqPcuV0s8rYixW+ZSYkhLCW6PTS/5Y+S/GlhXcbMblzPR5YG24jJLbQ/+mLPk3MSycFGe0+znn57Us+4CvxzOJundtQ9zu0XPc+OouuEPWJH1g4UJrk3FDVk6WbyiUrOzgU9EQYi33ALjHXy+LaR16aRPSRbJkXmIB/y7MFeQOODyw7uDaiiqKsJ8nN1bVQ6OOpuN+iEBxwT3vQ95I4w8pJZT4lcGswLZzcItLJkupMRGA8D9Bt/+yJsh/NqrBLLy+U+fjR02PxhYGS/9lcSw8cEXPByVTqhrO7hMJrZz3rzzogSrH4ZmsNDzul4C/6UvBttbYw+2LlYXorYCYX0k52TA0Rw78tTL0HParV1VpzXHLBpI3ogT2SoFch6eorC/HcYPWgBch+IoCtNIpwqss5DMFug94MlNf+6j1P8zq6y369bRMUrytbHlxbriXGC1rgjn2hQolkiEJhIx21Fm62kiLN7rDMZ/ACTxrS7Zals2PYzcZylSw7eRf4QZI30SWbssL8aUI7hXzEXuob2MN63F2k6atNBgekED5GIcVx2ba9nol4n2ng50PBCjW1C1hMmI5OzHZBCMjmHRGQcbYQCbwIMufurYm6zoMSUCp847emN9Wgap7rRzPl17L0NVJUf114uyilm4P+91yZKdCbUIj9VHktJh4V5S0q2pn56f8mN9ZWWQX4aoZtC6WrRJnZjpzywZFdamT9RD5ViVu+rcuGwrWnkwoPdjdTSktl2ShAuWRwgifJtH0 LTNRdkze PC8Ibu4NwBcES1ZMMz25k5WzrOxwoQYdc7OrfEtG35zPOT9AWdLCkKfbdWfHYYB5VaPI1n3q6RPtipQFB/APmrSyEgBnQ3mh/JDoKfCpt2Zs4YweNAzY2lRyAXK/TynQ8ZQgYvFjCuk3wLD9/zNQ6zw8KLlJmz5VSi1kzLXZprYj/jjIXNVItsezwS7F+JFFvdt/Op6F98Dv+QBueW5hdtczT/D1FbYqnk1jfa/Y2t+EsXzmPyLkvmRyYZRJ7Ct+5Zyczg6eO2eqrYiNBfCGAhncOzWth4Fj4TJ2du+zW03xbSxOPrt0uBdbUY0xXthVJQqQlmfbAR4I87rTa9T+iVOfm7qw1eVYJOTMuZnfaghFurf6+uepAov9LWM0ZOwZk0jthRdhxIqz1YB3dFy9epKtJySb7hxLZiS+XGW4GZ4QeM3RCSSW/OFy3aE806CMRPAp6WRXFm6AFDoNJb1PxiqiId1TtJcEmsBjN0JQAbAWZyBovoYMlHQCoSkXxJxppmLKufljb44q3T4XV9A8HvyoKIQVTTgz/9XsOvr5rhT30wYPViaR33plIuQ== 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: List-Subscribe: List-Unsubscribe: Fix some checkpatch complaints in the new iov_iter kunit tests: (1) Some lines had eight spaces instead of a tab at the start. (2) Checkpatch doesn't like (void*)(unsigned long)0xnnnnnULL, so switch to using POISON_POINTER_DELTA plus an offset instead. Reported-by: Johannes Thumshirn Signed-off-by: David Howells cc: Christoph Hellwig cc: Christian Brauner cc: Jens Axboe cc: Al Viro cc: David Hildenbrand cc: John Hubbard cc: Brendan Higgins cc: David Gow cc: linux-kselftest@vger.kernel.org cc: kunit-dev@googlegroups.com cc: linux-mm@kvack.org cc: linux-fsdevel@vger.kernel.org --- lib/kunit_iov_iter.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/kunit_iov_iter.c b/lib/kunit_iov_iter.c index 859b67c4d697..4a6c0efd33f5 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -53,7 +53,7 @@ static void *__init iov_kunit_create_buffer(struct kunit *test, void *buffer; pages = kunit_kcalloc(test, npages, sizeof(struct page *), GFP_KERNEL); - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pages); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pages); *ppages = pages; got = alloc_pages_bulk_array(GFP_KERNEL, npages, pages); @@ -63,7 +63,7 @@ static void *__init iov_kunit_create_buffer(struct kunit *test, } buffer = vmap(pages, npages, VM_MAP | VM_MAP_PUT_PAGES, PAGE_KERNEL); - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buffer); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buffer); kunit_add_action_or_reset(test, iov_kunit_unmap, buffer); return buffer; @@ -548,7 +548,7 @@ static void __init iov_kunit_extract_pages_kvec(struct kunit *test) size_t offset0 = LONG_MAX; for (i = 0; i < ARRAY_SIZE(pagelist); i++) - pagelist[i] = (void *)(unsigned long)0xaa55aa55aa55aa55ULL; + pagelist[i] = (void *)POISON_POINTER_DELTA + 0x5a; len = iov_iter_extract_pages(&iter, &pages, 100 * 1024, ARRAY_SIZE(pagelist), 0, &offset0); @@ -626,7 +626,7 @@ static void __init iov_kunit_extract_pages_bvec(struct kunit *test) size_t offset0 = LONG_MAX; for (i = 0; i < ARRAY_SIZE(pagelist); i++) - pagelist[i] = (void *)(unsigned long)0xaa55aa55aa55aa55ULL; + pagelist[i] = (void *)POISON_POINTER_DELTA + 0x5a; len = iov_iter_extract_pages(&iter, &pages, 100 * 1024, ARRAY_SIZE(pagelist), 0, &offset0); @@ -709,7 +709,7 @@ static void __init iov_kunit_extract_pages_xarray(struct kunit *test) size_t offset0 = LONG_MAX; for (i = 0; i < ARRAY_SIZE(pagelist); i++) - pagelist[i] = (void *)(unsigned long)0xaa55aa55aa55aa55ULL; + pagelist[i] = (void *)POISON_POINTER_DELTA + 0x5a; len = iov_iter_extract_pages(&iter, &pages, 100 * 1024, ARRAY_SIZE(pagelist), 0, &offset0); From patchwork Wed Nov 15 15:49: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: 13457011 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 EF5D1C2BB3F for ; Wed, 15 Nov 2023 15:50:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B35180019; Wed, 15 Nov 2023 10:50:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7631780018; Wed, 15 Nov 2023 10:50:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5DA9B80019; Wed, 15 Nov 2023 10:50:09 -0500 (EST) 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 4527680018 for ; Wed, 15 Nov 2023 10:50:09 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1663A160462 for ; Wed, 15 Nov 2023 15:50:09 +0000 (UTC) X-FDA: 81460624938.24.BFD8197 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 494C240020 for ; Wed, 15 Nov 2023 15:50:07 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EECGJoc9; 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=1700063407; 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=5b6pNIXvPusUJyKIJ79YNSk4ECrSg95WSD4lvAEAmQ9Z3sHdGxOKIL+QHMCnC3WlCmfdLK HRVWCofjXNibMfq25aP0A5lCtHQRaRvFMyAWsDD9oD8V8NinDNjUzHXDHBmUNCHg58b2rX 0/Yg543C7gO9IipMxYNwfGPDUvZWmKU= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EECGJoc9; 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=1700063407; a=rsa-sha256; cv=none; b=YYswdwHgMsaivn2lUhk34dO3oxeGQ8JLNxp1M/KVQcZnyxnllEJRI2fekCfmuxZc9QXVdK M2iaZjDE8JHEnOHVZFTvIYYftu1Q+c2IkRMQgXgt0FNQ10o35hdvqcxlpSWxExv2jf5a0z C79/5JUo40csfND47pORXeZ8Y/Om5xM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700063406; 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=EECGJoc9bJiPQOJmLuxqc0NTo8UKOW83p1nO4uVOoUZdmFF9rLm3P3aenRvOn7+Cvj3UqY NZXf+wvHVGFyVP6y9eqwHf9sSCmHMUNxFKNl9Mi8w0rFttq2/bcpAYZ4/MBhCcxOcxgQln YxgnPiiH5gg99jYYgDidyJjdY3tDhbk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-81-Uwpo4MoJOvqOauyzpGI_Bw-1; Wed, 15 Nov 2023 10:50:01 -0500 X-MC-Unique: Uwpo4MoJOvqOauyzpGI_Bw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1715F811E82; Wed, 15 Nov 2023 15:50:00 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8503F40C6EB9; Wed, 15 Nov 2023 15:49:57 +0000 (UTC) From: David Howells To: Christian Brauner Cc: David Howells , Jens Axboe , Al Viro , Linus Torvalds , Christoph Hellwig , 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: Wed, 15 Nov 2023 15:49:38 +0000 Message-ID: <20231115154946.3933808-3-dhowells@redhat.com> In-Reply-To: <20231115154946.3933808-1-dhowells@redhat.com> References: <20231115154946.3933808-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspamd-Queue-Id: 494C240020 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: redkny33hu3u4m5pogpn9zw8rm5nxexz X-HE-Tag: 1700063407-896925 X-HE-Meta: U2FsdGVkX1/g2OBVb2P3m3Mvgrt6Dv2Zorf2TIENEe9p5Z0ceAr6VyhUj6arXgcqwNddLXSpszOC1YqD3hII09MtXVGDgINFQKNYXmWKyzoAcupZzITbYmHkc0ZcDkV5NmVw07M2ARObOXKMqtWJ8F598MUykQ5eI9DdLon36gFYYq2/3msoqKc4Ns6UznBFMMr+oV65JDLdaG9/deZNcbC+qX/DtsJhwKq5F/J8gOINk0uc0FQIe3TB/ZOEn8vGhEnySZXCDgOXFCDykCTw3vFpjiDwhpLOvyCOQKrac6HEDkXfo+YOCJIEw53N/9LIhN+0RMS8X9XhOg6xWfq77exBvq2m21BP302vbveg+z3ddFP85w18TfoENll7HH+oEXmcgCFajuJWowZQaB8YOb7vgGOcsoTz3cB4377ciJgfNFQR1K2i87gFKkLuMeyuXDE38XbUBsBXtB3eUutaCyWwn03rgC/AkNXW8h9NW50m9XPfWMGsFe1XsdWdplDDgdXgqkQk6rF6tC20ZDKwBzF/wkYowk5bQN1ByFEZfoEi0T3NkdtBrUmQoEgbQknYjRdH6aU0s2wKRK0XHxdTO3v5MRMwCRqZg/aGygXUzGLdknLJPDo79eyLGy33AivRr7oigrgSDuY1SyxgrYmk037Yx8z+FYuO661jfGukYO3rwoPKBHfx8CPftAm8yXpNUvry+L1F+4P7jrR6lVpGymvCJlIwXG34xApWgdtxBxT23gJrPQbDJzGAZ4qbukAY5WD8dAcQByyMqFSOR02j1FUsyEhMUmXhSy3btir/BuqdHWpGE/HEukaL6Z1V+uDtMKGTJoJH0RJ2Qtx76aVKTLyIv3GayBCKi5Nirk3CkVRvvJazirMjno2uhPSGhvrsZFRj+tXhrz/Ad1RNIoc1rLH7wD2nXDHHvQDGcU8lvk/AI71dj0pPZuaf8fygVmTav12uJ3Ai92EHFGTBRT+ /HMCz1Pm dsUMnZRqdoyeSDTAySGeBXHGZdElBuN/4frB0WC/yp2gbROxmXzXk0AN0oThjqj1aCa1vgDJSyxjRQM3nakL+wacNOjGcr9htFs3kUBL+i2zKfxxlmHgMMo0cUlsSsCkWWfbpnJ+6Zwksz3+f9+/s7/jI+60toM9s8VnmbjCjfVDkPeXDT2kg9IdWDN67ep84NDEm4fFh5QLoMbZGwxJMfPalzCpbbtzj/+egQuSg6Vz7Jn+1WY1/tLO9kW6oFIssOfSbp/91bGZTi4QKIBGewUtzGIwcOvhAaoK5b4jm5X0v3UZwNjwfmzJVyp4xYsxVrMmPblj/Sl9Aa3j5UYIUvz1VNmAoYnobMPh9GDo2fTqgSJCYr0crCSE/wJDMWs23EhQHYNcvJjV/LIi7YdRVHZGu7QpT0vJzqyctPwcVrCyOOrBaMJ4Hh0gB/OuMvwhHRGPaPrzqE01L3a3Y+K379cUwkzTBL3ivzOwHiFP8EWSCS7fmOr83rz8fHop7XZ2uVnaj 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: List-Subscribe: List-Unsubscribe: Consolidate some of the repeated code snippets into helper functions to reduce the line count. Signed-off-by: David Howells cc: Christoph Hellwig cc: Christian Brauner cc: Jens Axboe cc: Al Viro cc: David Hildenbrand cc: John Hubbard cc: Brendan Higgins cc: David Gow cc: linux-kselftest@vger.kernel.org cc: kunit-dev@googlegroups.com cc: linux-mm@kvack.org cc: linux-fsdevel@vger.kernel.org --- lib/kunit_iov_iter.c | 189 +++++++++++++++++++------------------------ 1 file changed, 84 insertions(+), 105 deletions(-) diff --git a/lib/kunit_iov_iter.c b/lib/kunit_iov_iter.c index 4a6c0efd33f5..ee586eb652b4 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -19,18 +19,18 @@ MODULE_AUTHOR("David Howells "); MODULE_LICENSE("GPL"); struct kvec_test_range { - int from, to; + int page, from, to; }; static const struct kvec_test_range kvec_test_ranges[] = { - { 0x00002, 0x00002 }, - { 0x00027, 0x03000 }, - { 0x05193, 0x18794 }, - { 0x20000, 0x20000 }, - { 0x20000, 0x24000 }, - { 0x24000, 0x27001 }, - { 0x29000, 0xffffb }, - { 0xffffd, 0xffffe }, + { 0, 0x00002, 0x00002 }, + { 0, 0x00027, 0x03000 }, + { 0, 0x05193, 0x18794 }, + { 0, 0x20000, 0x20000 }, + { 0, 0x20000, 0x24000 }, + { 0, 0x24000, 0x27001 }, + { 0, 0x29000, 0xffffb }, + { 0, 0xffffd, 0xffffe }, { -1 } }; @@ -69,6 +69,57 @@ static void *__init iov_kunit_create_buffer(struct kunit *test, return buffer; } +/* + * Build the reference pattern in the scratch buffer that we expect to see in + * the iterator buffer (ie. the result of copy *to*). + */ +static void iov_kunit_build_to_reference_pattern(struct kunit *test, u8 *scratch, + size_t bufsize, + const struct kvec_test_range *pr) +{ + int i, patt = 0; + + memset(scratch, 0, bufsize); + for (; pr->page >= 0; pr++) + for (i = pr->from; i < pr->to; i++) + scratch[i] = pattern(patt++); +} + +/* + * Build the reference pattern in the iterator buffer that we expect to see in + * the scratch buffer (ie. the result of copy *from*). + */ +static void iov_kunit_build_from_reference_pattern(struct kunit *test, u8 *buffer, + size_t bufsize, + const struct kvec_test_range *pr) +{ + size_t i = 0, j; + + memset(buffer, 0, bufsize); + for (; pr->page >= 0; pr++) { + for (j = pr->from; j < pr->to; j++) { + buffer[i++] = pattern(j); + if (i >= bufsize) + return; + } + } +} + +/* + * Compare two kernel buffers to see that they're the same. + */ +static void iov_kunit_check_pattern(struct kunit *test, const u8 *buffer, + const u8 *scratch, size_t bufsize) +{ + size_t i; + + for (i = 0; i < bufsize; i++) { + KUNIT_EXPECT_EQ_MSG(test, buffer[i], scratch[i], "at i=%x", i); + if (buffer[i] != scratch[i]) + return; + } +} + static void __init iov_kunit_load_kvec(struct kunit *test, struct iov_iter *iter, int dir, struct kvec *kvec, unsigned int kvmax, @@ -79,7 +130,7 @@ static void __init iov_kunit_load_kvec(struct kunit *test, int i; for (i = 0; i < kvmax; i++, pr++) { - if (pr->from < 0) + if (pr->page < 0) break; KUNIT_ASSERT_GE(test, pr->to, pr->from); KUNIT_ASSERT_LE(test, pr->to, bufsize); @@ -97,13 +148,12 @@ static void __init iov_kunit_load_kvec(struct kunit *test, */ static void __init iov_kunit_copy_to_kvec(struct kunit *test) { - const struct kvec_test_range *pr; struct iov_iter iter; struct page **spages, **bpages; struct kvec kvec[8]; u8 *scratch, *buffer; size_t bufsize, npages, size, copied; - int i, patt; + int i; bufsize = 0x100000; npages = bufsize / PAGE_SIZE; @@ -125,20 +175,8 @@ static void __init iov_kunit_copy_to_kvec(struct kunit *test) KUNIT_EXPECT_EQ(test, iter.count, 0); KUNIT_EXPECT_EQ(test, iter.nr_segs, 0); - /* Build the expected image in the scratch buffer. */ - patt = 0; - memset(scratch, 0, bufsize); - for (pr = kvec_test_ranges; pr->from >= 0; pr++) - for (i = pr->from; i < pr->to; i++) - scratch[i] = pattern(patt++); - - /* Compare the images */ - for (i = 0; i < bufsize; i++) { - KUNIT_EXPECT_EQ_MSG(test, buffer[i], scratch[i], "at i=%x", i); - if (buffer[i] != scratch[i]) - return; - } - + iov_kunit_build_to_reference_pattern(test, scratch, bufsize, kvec_test_ranges); + iov_kunit_check_pattern(test, buffer, scratch, bufsize); KUNIT_SUCCEED(); } @@ -147,13 +185,12 @@ static void __init iov_kunit_copy_to_kvec(struct kunit *test) */ static void __init iov_kunit_copy_from_kvec(struct kunit *test) { - const struct kvec_test_range *pr; struct iov_iter iter; struct page **spages, **bpages; struct kvec kvec[8]; u8 *scratch, *buffer; size_t bufsize, npages, size, copied; - int i, j; + int i; bufsize = 0x100000; npages = bufsize / PAGE_SIZE; @@ -175,25 +212,8 @@ static void __init iov_kunit_copy_from_kvec(struct kunit *test) KUNIT_EXPECT_EQ(test, iter.count, 0); KUNIT_EXPECT_EQ(test, iter.nr_segs, 0); - /* Build the expected image in the main buffer. */ - i = 0; - memset(buffer, 0, bufsize); - for (pr = kvec_test_ranges; pr->from >= 0; pr++) { - for (j = pr->from; j < pr->to; j++) { - buffer[i++] = pattern(j); - if (i >= bufsize) - goto stop; - } - } -stop: - - /* Compare the images */ - for (i = 0; i < bufsize; i++) { - KUNIT_EXPECT_EQ_MSG(test, scratch[i], buffer[i], "at i=%x", i); - if (scratch[i] != buffer[i]) - return; - } - + iov_kunit_build_from_reference_pattern(test, buffer, bufsize, kvec_test_ranges); + iov_kunit_check_pattern(test, buffer, scratch, bufsize); KUNIT_SUCCEED(); } @@ -210,7 +230,7 @@ static const struct bvec_test_range bvec_test_ranges[] = { { 5, 0x0000, 0x1000 }, { 6, 0x0000, 0x0ffb }, { 6, 0x0ffd, 0x0ffe }, - { -1, -1, -1 } + { -1 } }; static void __init iov_kunit_load_bvec(struct kunit *test, @@ -225,7 +245,7 @@ static void __init iov_kunit_load_bvec(struct kunit *test, int i; for (i = 0; i < bvmax; i++, pr++) { - if (pr->from < 0) + if (pr->page < 0) break; KUNIT_ASSERT_LT(test, pr->page, npages); KUNIT_ASSERT_LT(test, pr->page * PAGE_SIZE, bufsize); @@ -288,20 +308,14 @@ static void __init iov_kunit_copy_to_bvec(struct kunit *test) b = 0; patt = 0; memset(scratch, 0, bufsize); - for (pr = bvec_test_ranges; pr->from >= 0; pr++, b++) { + for (pr = bvec_test_ranges; pr->page >= 0; pr++, b++) { u8 *p = scratch + pr->page * PAGE_SIZE; for (i = pr->from; i < pr->to; i++) p[i] = pattern(patt++); } - /* Compare the images */ - for (i = 0; i < bufsize; i++) { - KUNIT_EXPECT_EQ_MSG(test, buffer[i], scratch[i], "at i=%x", i); - if (buffer[i] != scratch[i]) - return; - } - + iov_kunit_check_pattern(test, buffer, scratch, bufsize); KUNIT_SUCCEED(); } @@ -341,7 +355,7 @@ static void __init iov_kunit_copy_from_bvec(struct kunit *test) /* Build the expected image in the main buffer. */ i = 0; memset(buffer, 0, bufsize); - for (pr = bvec_test_ranges; pr->from >= 0; pr++) { + for (pr = bvec_test_ranges; pr->page >= 0; pr++) { size_t patt = pr->page * PAGE_SIZE; for (j = pr->from; j < pr->to; j++) { @@ -352,13 +366,7 @@ static void __init iov_kunit_copy_from_bvec(struct kunit *test) } stop: - /* Compare the images */ - for (i = 0; i < bufsize; i++) { - KUNIT_EXPECT_EQ_MSG(test, scratch[i], buffer[i], "at i=%x", i); - if (scratch[i] != buffer[i]) - return; - } - + iov_kunit_check_pattern(test, buffer, scratch, bufsize); KUNIT_SUCCEED(); } @@ -409,7 +417,7 @@ static void __init iov_kunit_copy_to_xarray(struct kunit *test) struct page **spages, **bpages; u8 *scratch, *buffer; size_t bufsize, npages, size, copied; - int i, patt; + int i; bufsize = 0x100000; npages = bufsize / PAGE_SIZE; @@ -426,7 +434,7 @@ static void __init iov_kunit_copy_to_xarray(struct kunit *test) iov_kunit_load_xarray(test, &iter, READ, xarray, bpages, npages); i = 0; - for (pr = kvec_test_ranges; pr->from >= 0; pr++) { + for (pr = kvec_test_ranges; pr->page >= 0; pr++) { size = pr->to - pr->from; KUNIT_ASSERT_LE(test, pr->to, bufsize); @@ -439,20 +447,8 @@ static void __init iov_kunit_copy_to_xarray(struct kunit *test) i += size; } - /* Build the expected image in the scratch buffer. */ - patt = 0; - memset(scratch, 0, bufsize); - for (pr = kvec_test_ranges; pr->from >= 0; pr++) - for (i = pr->from; i < pr->to; i++) - scratch[i] = pattern(patt++); - - /* Compare the images */ - for (i = 0; i < bufsize; i++) { - KUNIT_EXPECT_EQ_MSG(test, buffer[i], scratch[i], "at i=%x", i); - if (buffer[i] != scratch[i]) - return; - } - + iov_kunit_build_to_reference_pattern(test, scratch, bufsize, kvec_test_ranges); + iov_kunit_check_pattern(test, buffer, scratch, bufsize); KUNIT_SUCCEED(); } @@ -467,7 +463,7 @@ static void __init iov_kunit_copy_from_xarray(struct kunit *test) struct page **spages, **bpages; u8 *scratch, *buffer; size_t bufsize, npages, size, copied; - int i, j; + int i; bufsize = 0x100000; npages = bufsize / PAGE_SIZE; @@ -484,7 +480,7 @@ static void __init iov_kunit_copy_from_xarray(struct kunit *test) iov_kunit_load_xarray(test, &iter, READ, xarray, bpages, npages); i = 0; - for (pr = kvec_test_ranges; pr->from >= 0; pr++) { + for (pr = kvec_test_ranges; pr->page >= 0; pr++) { size = pr->to - pr->from; KUNIT_ASSERT_LE(test, pr->to, bufsize); @@ -497,25 +493,8 @@ static void __init iov_kunit_copy_from_xarray(struct kunit *test) i += size; } - /* Build the expected image in the main buffer. */ - i = 0; - memset(buffer, 0, bufsize); - for (pr = kvec_test_ranges; pr->from >= 0; pr++) { - for (j = pr->from; j < pr->to; j++) { - buffer[i++] = pattern(j); - if (i >= bufsize) - goto stop; - } - } -stop: - - /* Compare the images */ - for (i = 0; i < bufsize; i++) { - KUNIT_EXPECT_EQ_MSG(test, scratch[i], buffer[i], "at i=%x", i); - if (scratch[i] != buffer[i]) - return; - } - + iov_kunit_build_from_reference_pattern(test, buffer, bufsize, kvec_test_ranges); + iov_kunit_check_pattern(test, buffer, scratch, bufsize); KUNIT_SUCCEED(); } @@ -573,7 +552,7 @@ static void __init iov_kunit_extract_pages_kvec(struct kunit *test) while (from == pr->to) { pr++; from = pr->from; - if (from < 0) + if (pr->page < 0) goto stop; } ix = from / PAGE_SIZE; @@ -651,7 +630,7 @@ static void __init iov_kunit_extract_pages_bvec(struct kunit *test) while (from == pr->to) { pr++; from = pr->from; - if (from < 0) + if (pr->page < 0) goto stop; } ix = pr->page + from / PAGE_SIZE; @@ -698,7 +677,7 @@ static void __init iov_kunit_extract_pages_xarray(struct kunit *test) iov_kunit_create_buffer(test, &bpages, npages); iov_kunit_load_xarray(test, &iter, READ, xarray, bpages, npages); - for (pr = kvec_test_ranges; pr->from >= 0; pr++) { + for (pr = kvec_test_ranges; pr->page >= 0; pr++) { from = pr->from; size = pr->to - from; KUNIT_ASSERT_LE(test, pr->to, bufsize); From patchwork Wed Nov 15 15:49:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13457012 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 D6E82C5AD4C for ; Wed, 15 Nov 2023 15:50:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A26D8001A; Wed, 15 Nov 2023 10:50:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 62A4E80018; Wed, 15 Nov 2023 10:50:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 47C128001A; Wed, 15 Nov 2023 10:50:12 -0500 (EST) 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 32C1A80018 for ; Wed, 15 Nov 2023 10:50:12 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0F3E51CAFD7 for ; Wed, 15 Nov 2023 15:50:11 +0000 (UTC) X-FDA: 81460625064.27.F8AAC46 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf24.hostedemail.com (Postfix) with ESMTP id F1D14180017 for ; Wed, 15 Nov 2023 15:50:06 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Q/WfnMNr"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.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=1700063410; 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=dXebzez1P3lRMdlfunolPOYpkPX/Miekgno8d+/bRTIUvCR2Xaz0Kxs21Kz7In/YVubl6u /eKisw0+C/T7jAv4t8F54LGoNvYxVHE4Qz8Je3rqvN+4HoL2VfNvLJ4trLFzzKvAFJ4UDX 3oEz6wEsx2kO4JOk4FGV8YPaRdIG9go= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Q/WfnMNr"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.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=1700063410; a=rsa-sha256; cv=none; b=OVk66n721HAwssliBCCwirTR+4uuZIgKAM/hSyi37qrfIr3HVjnoC1GJ4dykD7nmnF0NL5 dxk39ibSHdZmEX8XQa2pSAgsBtwgSV3dtivS5BBEZbN2llnjil/+HV0jPJZUUHdHY4+rsQ d0Cn1Yh5ivXxmdpkTauaXF3YdXW8gCs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700063405; 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=Q/WfnMNri/VjKCHezVKK8T4TVSrHqTDNUUbUojUm6ahF6aE3yvGag9lZsFLcqIoA1MMDXE hYtcHp1ZYnMs0R+BNA+huaB2sHZby/98sj1arbuJIoia8R14/q1IoOTjk2DTn0OPHvQ+IF qqe/yMeJzr4suCudePGJPVucHdFMZKw= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-587-tOqBedN5MdGxlitEdx1MDg-1; Wed, 15 Nov 2023 10:50:04 -0500 X-MC-Unique: tOqBedN5MdGxlitEdx1MDg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 50BA23C000BA; Wed, 15 Nov 2023 15:50:03 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF347C15881; Wed, 15 Nov 2023 15:50:00 +0000 (UTC) From: David Howells To: Christian Brauner Cc: David Howells , Jens Axboe , Al Viro , Linus Torvalds , Christoph Hellwig , 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: Wed, 15 Nov 2023 15:49:39 +0000 Message-ID: <20231115154946.3933808-4-dhowells@redhat.com> In-Reply-To: <20231115154946.3933808-1-dhowells@redhat.com> References: <20231115154946.3933808-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Rspamd-Queue-Id: F1D14180017 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: wtx4pgb3ynhp9guzffrh8fiqfgnauuw3 X-HE-Tag: 1700063406-547651 X-HE-Meta: U2FsdGVkX196AVErikwACq1AREy6j5arpc5QjITgSpyajpv+TZqKymUil0MBJP0xGBIWjHE5aWSqXw/IW+CWlTniMU6qBGeF6ZMY6stQ7W6UHg1PBOwj0U0MXvpGh5EIvvnyz4Wck3qfP7rLgeYma9BQzFRc6kzMENrr06YnRO1WEMGR4+R2TvmPti9JY0o4WYaQ3xrl4Fns7a6hxbOOwNzOfu5f0l6IVkOGzNRY+6lTYXajAGeCUbwQE2FtZKo5koou70z0dg/qY990H8qhNi2ChjRWrQWS9s8dJISu0Jv06jKO7uPaV5pY6PGfRdrQIjPAnWHICXBRTayuCh/cX9g5n2u+BM9e2/m5T1IhdrF4ExAHqwvAYwOGTMLWKgLDzmGqJyKCIXGghbg+cZ1vk68U8yT53OfI7n0NqnvfQnHbKg6+iMBVFZdVkh/ylXN+fvIfAyDcHvC+Qdxq9yMaDI6acNfXsVNz9rya5uTAlyrlfeSwwU7IVRsFsVbkRB016eBL/zTzifMNKyhG+elyQ6a5I5R1H/r29HYkhoURCORyE8cTVasBFyUWsBtfoNvtHeuFmmmwK6Y+ektFVaW7N3jjw0L8R/uGstNEy4D8ZI7Y0fei4dxec8MLNt6wsay+R8HH+sDlCM82/XonDXuPNIQI1qm79EIfarompDtY1GomN9D4sys04rn2FUJhGZC0YZmKyKoYOa5B+m4Ys8/takIKKZjmE2X88AAt5lYZ3eW7zRRt2TYBeoZc4VmJKcOCMXF0n4bmR9CtDuu39VnEG2DsirsneQpJZTOUnG8IsZ8sGVHglEx6KWSv3OQFbzuzA5Qoo249An8ACId692yUeF3jHXFP4tdScYlYl5e7mZyfOQ2goNfUGPPHP/VD6SCFGwZtAFEUm+wzREoCd37lsoQB1z1AUZtG3mTeqI2kHzqpTkGZeA+5jzFPFYumF0nIeYwYsBseLw+opXcZb5d 0YVr6Gm1 ChYfebHqCNf//SR/fEpC9/ZILtPQ4uYhBnzcdKpUMWsFISJMNDwFkL342Gk3Ln8obmD+ZCVzjBUD+rlzNa2SZMLA/gMIF27+qczBeMqZ8xw0b+imgoHIKSf8QqCCOZFC9SBWGHktya3SBsxGgO8tiRNR5POc47GFsnApfdhmwayOce9Kthc03ZhXew/8tYD3b2a6/wmlMaf83oEKA7CLwpjwAw62Qnh9IgrxgqHGZtNWsB84XNv90h/dYSAWjOq0ltpy0RNOITFALS3h2PB5OTPIeIcMcXJAtEdWqFm7W+99CjvB/86GhmQmH2qhG8NA82PKTqoDD6RlY8U1j185g+ZxhxDAYUcA5wWLtjEJ/CYSqTW3UZMXgc+RbBEHijT/Ool/nRrXLtsHhsEJyc8MmnQ2+0TdbyNKgd5oSt4NLFsNTXqOUtKCshZxmPW8YZftA1f8WSuBE8XY0+1WxIAVk0l73FIWcb0FhVStXSZqgmO0mz7chbBsrZnz3Jfd02QFem8Ci 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: List-Subscribe: List-Unsubscribe: Consolidate the test vector struct in the kunit tests so that the bvec pattern check helpers can share with the kvec check helpers. Signed-off-by: David Howells cc: Christoph Hellwig cc: Christian Brauner cc: Jens Axboe cc: Al Viro cc: David Hildenbrand cc: John Hubbard cc: Brendan Higgins cc: David Gow cc: linux-kselftest@vger.kernel.org cc: kunit-dev@googlegroups.com cc: linux-mm@kvack.org cc: linux-fsdevel@vger.kernel.org --- lib/kunit_iov_iter.c | 90 ++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/lib/kunit_iov_iter.c b/lib/kunit_iov_iter.c index ee586eb652b4..4925ca37cde6 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -18,22 +18,46 @@ MODULE_DESCRIPTION("iov_iter testing"); MODULE_AUTHOR("David Howells "); MODULE_LICENSE("GPL"); -struct kvec_test_range { +struct iov_kunit_range { int page, from, to; }; -static const struct kvec_test_range kvec_test_ranges[] = { - { 0, 0x00002, 0x00002 }, - { 0, 0x00027, 0x03000 }, - { 0, 0x05193, 0x18794 }, - { 0, 0x20000, 0x20000 }, - { 0, 0x20000, 0x24000 }, - { 0, 0x24000, 0x27001 }, - { 0, 0x29000, 0xffffb }, - { 0, 0xffffd, 0xffffe }, +/* + * Ranges that to use in tests where we have address/offset ranges to play + * with (ie. KVEC) or where we have a single blob that we can copy + * arbitrary chunks of (ie. XARRAY). + */ +static const struct iov_kunit_range kvec_test_ranges[] = { + { 0, 0x00002, 0x00002 }, /* Start with an empty range */ + { 0, 0x00027, 0x03000 }, /* Midpage to page end */ + { 0, 0x05193, 0x18794 }, /* Midpage to midpage */ + { 0, 0x20000, 0x20000 }, /* Empty range in the middle */ + { 0, 0x20000, 0x24000 }, /* Page start to page end */ + { 0, 0x24000, 0x27001 }, /* Page end to midpage */ + { 0, 0x29000, 0xffffb }, /* Page start to midpage */ + { 0, 0xffffd, 0xffffe }, /* Almost contig to last, ending in same page */ { -1 } }; +/* + * Ranges that to use in tests where we have a list of partial pages to + * play with (ie. BVEC). + */ +static const struct iov_kunit_range bvec_test_ranges[] = { + { 0, 0x0002, 0x0002 }, /* Start with an empty range */ + { 1, 0x0027, 0x0893 }, /* Random part of page */ + { 2, 0x0193, 0x0794 }, /* Random part of page */ + { 3, 0x0000, 0x1000 }, /* Full page */ + { 4, 0x0000, 0x1000 }, /* Full page logically contig to last */ + { 5, 0x0000, 0x1000 }, /* Full page logically contig to last */ + { 6, 0x0000, 0x0ffb }, /* Part page logically contig to last */ + { 6, 0x0ffd, 0x0ffe }, /* Part of prev page, but not quite contig */ + { -1 } +}; + +/* + * The pattern to fill with. + */ static inline u8 pattern(unsigned long x) { return x & 0xff; @@ -44,6 +68,9 @@ static void iov_kunit_unmap(void *data) vunmap(data); } +/* + * Create a buffer out of some pages and return a vmap'd pointer to it. + */ static void *__init iov_kunit_create_buffer(struct kunit *test, struct page ***ppages, size_t npages) @@ -75,7 +102,7 @@ static void *__init iov_kunit_create_buffer(struct kunit *test, */ static void iov_kunit_build_to_reference_pattern(struct kunit *test, u8 *scratch, size_t bufsize, - const struct kvec_test_range *pr) + const struct iov_kunit_range *pr) { int i, patt = 0; @@ -91,7 +118,7 @@ static void iov_kunit_build_to_reference_pattern(struct kunit *test, u8 *scratch */ static void iov_kunit_build_from_reference_pattern(struct kunit *test, u8 *buffer, size_t bufsize, - const struct kvec_test_range *pr) + const struct iov_kunit_range *pr) { size_t i = 0, j; @@ -124,7 +151,7 @@ static void __init iov_kunit_load_kvec(struct kunit *test, struct iov_iter *iter, int dir, struct kvec *kvec, unsigned int kvmax, void *buffer, size_t bufsize, - const struct kvec_test_range *pr) + const struct iov_kunit_range *pr) { size_t size = 0; int i; @@ -217,28 +244,12 @@ static void __init iov_kunit_copy_from_kvec(struct kunit *test) KUNIT_SUCCEED(); } -struct bvec_test_range { - int page, from, to; -}; - -static const struct bvec_test_range bvec_test_ranges[] = { - { 0, 0x0002, 0x0002 }, - { 1, 0x0027, 0x0893 }, - { 2, 0x0193, 0x0794 }, - { 3, 0x0000, 0x1000 }, - { 4, 0x0000, 0x1000 }, - { 5, 0x0000, 0x1000 }, - { 6, 0x0000, 0x0ffb }, - { 6, 0x0ffd, 0x0ffe }, - { -1 } -}; - static void __init iov_kunit_load_bvec(struct kunit *test, struct iov_iter *iter, int dir, struct bio_vec *bvec, unsigned int bvmax, struct page **pages, size_t npages, size_t bufsize, - const struct bvec_test_range *pr) + const struct iov_kunit_range *pr) { struct page *can_merge = NULL, *page; size_t size = 0; @@ -276,13 +287,13 @@ static void __init iov_kunit_load_bvec(struct kunit *test, */ static void __init iov_kunit_copy_to_bvec(struct kunit *test) { - const struct bvec_test_range *pr; + const struct iov_kunit_range *pr; struct iov_iter iter; struct bio_vec bvec[8]; struct page **spages, **bpages; u8 *scratch, *buffer; size_t bufsize, npages, size, copied; - int i, b, patt; + int i, patt; bufsize = 0x100000; npages = bufsize / PAGE_SIZE; @@ -305,10 +316,9 @@ static void __init iov_kunit_copy_to_bvec(struct kunit *test) KUNIT_EXPECT_EQ(test, iter.nr_segs, 0); /* Build the expected image in the scratch buffer. */ - b = 0; patt = 0; memset(scratch, 0, bufsize); - for (pr = bvec_test_ranges; pr->page >= 0; pr++, b++) { + for (pr = bvec_test_ranges; pr->page >= 0; pr++) { u8 *p = scratch + pr->page * PAGE_SIZE; for (i = pr->from; i < pr->to; i++) @@ -324,7 +334,7 @@ static void __init iov_kunit_copy_to_bvec(struct kunit *test) */ static void __init iov_kunit_copy_from_bvec(struct kunit *test) { - const struct bvec_test_range *pr; + const struct iov_kunit_range *pr; struct iov_iter iter; struct bio_vec bvec[8]; struct page **spages, **bpages; @@ -411,7 +421,7 @@ static struct xarray *iov_kunit_create_xarray(struct kunit *test) */ static void __init iov_kunit_copy_to_xarray(struct kunit *test) { - const struct kvec_test_range *pr; + const struct iov_kunit_range *pr; struct iov_iter iter; struct xarray *xarray; struct page **spages, **bpages; @@ -457,7 +467,7 @@ static void __init iov_kunit_copy_to_xarray(struct kunit *test) */ static void __init iov_kunit_copy_from_xarray(struct kunit *test) { - const struct kvec_test_range *pr; + const struct iov_kunit_range *pr; struct iov_iter iter; struct xarray *xarray; struct page **spages, **bpages; @@ -503,7 +513,7 @@ static void __init iov_kunit_copy_from_xarray(struct kunit *test) */ static void __init iov_kunit_extract_pages_kvec(struct kunit *test) { - const struct kvec_test_range *pr; + const struct iov_kunit_range *pr; struct iov_iter iter; struct page **bpages, *pagelist[8], **pages = pagelist; struct kvec kvec[8]; @@ -583,7 +593,7 @@ static void __init iov_kunit_extract_pages_kvec(struct kunit *test) */ static void __init iov_kunit_extract_pages_bvec(struct kunit *test) { - const struct bvec_test_range *pr; + const struct iov_kunit_range *pr; struct iov_iter iter; struct page **bpages, *pagelist[8], **pages = pagelist; struct bio_vec bvec[8]; @@ -661,7 +671,7 @@ static void __init iov_kunit_extract_pages_bvec(struct kunit *test) */ static void __init iov_kunit_extract_pages_xarray(struct kunit *test) { - const struct kvec_test_range *pr; + const struct iov_kunit_range *pr; struct iov_iter iter; struct xarray *xarray; struct page **bpages, *pagelist[8], **pages = pagelist; From patchwork Wed Nov 15 15:49:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13457013 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 60B14C54FB9 for ; Wed, 15 Nov 2023 15:50:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 877FD8001B; Wed, 15 Nov 2023 10:50:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8249080018; Wed, 15 Nov 2023 10:50:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 650998001B; Wed, 15 Nov 2023 10:50:13 -0500 (EST) 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 4FBB680018 for ; Wed, 15 Nov 2023 10:50:13 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2B16A402C3 for ; Wed, 15 Nov 2023 15:50:13 +0000 (UTC) X-FDA: 81460625106.14.AB11871 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 72BF7180009 for ; Wed, 15 Nov 2023 15:50:11 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Cv7H3z7V; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700063411; a=rsa-sha256; cv=none; b=jaxWyFNOh7PI4lLkw3id4EdDlHiS2kIAESrouxpJQRTw+INcvL0aaXbDhx0S+ttDyOQRdL b+0KwLcRX0YuUjJP2Y1dPS2ddo+OIwFGMBCvjzf9rwY8t+cwas1KiRqFDiAGmR7tY64XEO IDEHGiHEGLytBkYl8HtLLMOeg+dEIrc= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Cv7H3z7V; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700063411; 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=4wRSRX6x8/CYCrNesVUII20BT5Wyv2nIxlOVAZMMtNzmJ1Jnpi0Dx3JBX6UcDSEADQMFvy NXW8NCMn4m1WACrMnmWZWEtxt7jXqwRhjjLuiLPUeIBd4aCg0D9hKYKTZzP1Qeh/uwh7bs MOGB+gzpvBgmqioYe3cvef0EX+m89hM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700063410; 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=Cv7H3z7VaT0hCmJX7AfrkvUWK2WKVOjLBn3R1K/KNslnGhv1r2rnaekHcjt0/4rPz/clPn Oo0bN4vnwwPDO3rrK0Q3MtTNXj6wWjl4g9kBqAN2iwy4OHTaRht0tL3rwFISPBWrtp6vki pBWZpJqPVOA0wV4h9ieXWZ+jIeJLlYI= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-637-gyuK2To_O1O0ylvqZp2Mmg-1; Wed, 15 Nov 2023 10:50:07 -0500 X-MC-Unique: gyuK2To_O1O0ylvqZp2Mmg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 780DE280FEC2; Wed, 15 Nov 2023 15:50:06 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE6DB492BFD; Wed, 15 Nov 2023 15:50:03 +0000 (UTC) From: David Howells To: Christian Brauner Cc: David Howells , Jens Axboe , Al Viro , Linus Torvalds , Christoph Hellwig , 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: Wed, 15 Nov 2023 15:49:40 +0000 Message-ID: <20231115154946.3933808-5-dhowells@redhat.com> In-Reply-To: <20231115154946.3933808-1-dhowells@redhat.com> References: <20231115154946.3933808-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 72BF7180009 X-Stat-Signature: 1tfsmz98ijguzuiastzf4tbeb4m8p6ow X-HE-Tag: 1700063411-267389 X-HE-Meta: U2FsdGVkX19ePeutZ23INnQzob9MqJaEFVGAnATbCfTQrz/wVU3zGoJUeLK4zaK9ksd+8/6lTPxPM1PuNs6s2MTTNqRO/mty9OxyCdpsd7+0YB5pf5rm/3nrnGJ5OkfyfSWHcciMcccSoVTsGsjLXkxtP9jo7oQw5tws4wtO0LTGLnjTubJIIAkcDX2jvBkFahdV2HLUJDVFb4QKOpWTBAzlicAfWrvY0zasV6Mz/leWEuwnDLNEDNglVebeoO0eag8i6uC1p7RknQkEmXQt8dQql5SJT/smCiMS2EcHiIDNfuYvbsM+MitYyZKn1lFFR/IrAwtDCzCbHJVf0ROEEVfzmYs2ckbNdZM0zb4RAKCiH8IZYH/Q38RGQ67X5VdJtqwGmQIlkTZflA90VOyv0vsNpLHeitwXjXiTRHEftvwVqmKVeQkei2ZCGpmKk/1rn8NW+qqbyrrqYgAh+R6BJmkOtquMry3xYYSOci1hRy1WFF8CJG3wdbDBed1y69cVpZj8HR5HhOgRVZAqCS7iaD94RICOvvLwJKOwM5HFiPGLGzQUqQrfc0iE9JPpZ+qdWTReVPo0xXmKbgr/rObADfYaKLszYUJ976Kfm3pPI3x+d9xvm59iUSExA7ykcFEbm/maq9EabJfQztMS3VwLo4G0JFWCjHSIY9P6Xrdj6S/ChNa9iycBwXI6uvJrrIg35+iQq3YGTNYpmiz/mdRYCozq8YobMQr9zNZOoBLdBWpGwA4nCK7ilaq/j0R0QQZkaaORbBwRebYxFdsdSQ2iaZOgZI9/mn60buCkcykJMQosa3LiyhOE+GdzgXXhWhE9D/Qf5GTUR1samIdDhICIGHzzdYBvhrFiJcYCT8Mu4CYi6RDFAek3jAj3SbSUPAIretKYWIe6GsOPQDhMovWE2+xRBmG/1s6CHywBJbO47VMsQnEHONEsKuuJsWWMmJCfTzppKuNz7MQOdjmzYlh 7jKzLv2g N4s3IT3wGh4cd+VM9FaPxSNBXm9tNSIJ/zfjazBgaip7+VV+C3qNWaaErxEM09JkWepKlorbYzi7GJKa2aOnm3Nq8coaEWDDsCYapvVgEe/lgLW8vXecf7kgUzR6MDqbrqoEdLjRcUYR2w+BapSjjoz1Mud+08GnupSceb70aStqLDWmS6B8pPDKyaPnDCviHis11ovV8sDlwMwoLaIYMzO8dOqSMaXlcylj1UXkK7prsfnrh1Xn5sSwB/Br40fCDwohXnxQe+vvF6UAUux4vt8rQroiSlPc9gtsaGJ9M1bOgWa1v9qcXGA/lhHQllWWqRUnZV96gzDuLMXUeOFY+FjLRkr+BiKLX9hdHoanv9HRuMUzzH2FtwMzckXe0e27LhOq7B5dsNRirD8grqdsQx1ag33Fr78cntT+MSHCEq2ai0C4x+2tnAOyDiNoCLNcbjNGzHqdesE9uM6YWliHsZEyvI2+agURu9NukQXSLcRvG4AGgSPRnMc0rOy6DErGGG7uw 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: List-Subscribe: List-Unsubscribe: Make the BVEC-testing functions use the consolidated pattern checking functions to reduce the amount of duplicated code. Signed-off-by: David Howells cc: Christoph Hellwig cc: Christian Brauner cc: Jens Axboe cc: Al Viro cc: David Hildenbrand cc: John Hubbard cc: Brendan Higgins cc: David Gow cc: linux-kselftest@vger.kernel.org cc: kunit-dev@googlegroups.com cc: linux-mm@kvack.org cc: linux-fsdevel@vger.kernel.org --- lib/kunit_iov_iter.c | 42 +++++++++++------------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/lib/kunit_iov_iter.c b/lib/kunit_iov_iter.c index 4925ca37cde6..eb86371b67d0 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -107,9 +107,11 @@ static void iov_kunit_build_to_reference_pattern(struct kunit *test, u8 *scratch int i, patt = 0; memset(scratch, 0, bufsize); - for (; pr->page >= 0; pr++) + for (; pr->page >= 0; pr++) { + u8 *p = scratch + pr->page * PAGE_SIZE; for (i = pr->from; i < pr->to; i++) - scratch[i] = pattern(patt++); + p[i] = pattern(patt++); + } } /* @@ -124,8 +126,10 @@ static void iov_kunit_build_from_reference_pattern(struct kunit *test, u8 *buffe memset(buffer, 0, bufsize); for (; pr->page >= 0; pr++) { + size_t patt = pr->page * PAGE_SIZE; + for (j = pr->from; j < pr->to; j++) { - buffer[i++] = pattern(j); + buffer[i++] = pattern(patt + j); if (i >= bufsize) return; } @@ -287,13 +291,12 @@ static void __init iov_kunit_load_bvec(struct kunit *test, */ static void __init iov_kunit_copy_to_bvec(struct kunit *test) { - const struct iov_kunit_range *pr; struct iov_iter iter; struct bio_vec bvec[8]; struct page **spages, **bpages; u8 *scratch, *buffer; size_t bufsize, npages, size, copied; - int i, patt; + int i; bufsize = 0x100000; npages = bufsize / PAGE_SIZE; @@ -315,16 +318,7 @@ static void __init iov_kunit_copy_to_bvec(struct kunit *test) KUNIT_EXPECT_EQ(test, iter.count, 0); KUNIT_EXPECT_EQ(test, iter.nr_segs, 0); - /* Build the expected image in the scratch buffer. */ - patt = 0; - memset(scratch, 0, bufsize); - for (pr = bvec_test_ranges; pr->page >= 0; pr++) { - u8 *p = scratch + pr->page * PAGE_SIZE; - - for (i = pr->from; i < pr->to; i++) - p[i] = pattern(patt++); - } - + iov_kunit_build_to_reference_pattern(test, scratch, bufsize, bvec_test_ranges); iov_kunit_check_pattern(test, buffer, scratch, bufsize); KUNIT_SUCCEED(); } @@ -334,13 +328,12 @@ static void __init iov_kunit_copy_to_bvec(struct kunit *test) */ static void __init iov_kunit_copy_from_bvec(struct kunit *test) { - const struct iov_kunit_range *pr; struct iov_iter iter; struct bio_vec bvec[8]; struct page **spages, **bpages; u8 *scratch, *buffer; size_t bufsize, npages, size, copied; - int i, j; + int i; bufsize = 0x100000; npages = bufsize / PAGE_SIZE; @@ -362,20 +355,7 @@ static void __init iov_kunit_copy_from_bvec(struct kunit *test) KUNIT_EXPECT_EQ(test, iter.count, 0); KUNIT_EXPECT_EQ(test, iter.nr_segs, 0); - /* Build the expected image in the main buffer. */ - i = 0; - memset(buffer, 0, bufsize); - for (pr = bvec_test_ranges; pr->page >= 0; pr++) { - size_t patt = pr->page * PAGE_SIZE; - - for (j = pr->from; j < pr->to; j++) { - buffer[i++] = pattern(patt + j); - if (i >= bufsize) - goto stop; - } - } -stop: - + iov_kunit_build_from_reference_pattern(test, buffer, bufsize, bvec_test_ranges); iov_kunit_check_pattern(test, buffer, scratch, bufsize); KUNIT_SUCCEED(); } From patchwork Wed Nov 15 15:49:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13457014 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 D4E4FC2BB3F for ; Wed, 15 Nov 2023 15:50:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A1578001C; Wed, 15 Nov 2023 10:50:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6501280018; Wed, 15 Nov 2023 10:50:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C9568001C; Wed, 15 Nov 2023 10:50:19 -0500 (EST) 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 36B0A80018 for ; Wed, 15 Nov 2023 10:50:19 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0294AA02D5 for ; Wed, 15 Nov 2023 15:50:18 +0000 (UTC) X-FDA: 81460625358.22.FCC5E5C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf21.hostedemail.com (Postfix) with ESMTP id 2EEC61C000D for ; Wed, 15 Nov 2023 15:50:15 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IoVpORLK; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700063416; 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=b3ihm64DLhXgEo21yeb6GRZDfRI7P6/1vvxJ7ZUFSPA=; b=E3iFQdzB2MZXi8Z/QJF3YRdlPCLjRPT9cu9NiPWwOqr1qUviUbphqDpsrj1Sc8CSDLgNpx Rqh/OVRY5Kg2J7/5/vM9mR1ipXaXQu8Qe+IoNEGd7+8IfAuaNT/LP3My7uyslFzVS9oQhh VkaBg3G1hVll5JO2+qyUKEGwV0ZjxaE= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IoVpORLK; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700063416; a=rsa-sha256; cv=none; b=NJvZb+GLHeAylz2jFvMVfkElrvYnHZfexPT7qVEmGBs0j/vpBWBaw8TOoPqG2QCdbQdOTE mR1wYHbbFH015VCG9imxT64q6AwRsYtuYgzeWhuqCeDD+hpOo6DsPp5EQvcVz2SbmWSGBu 3dgLWS2JSmUg91JLo3HkS//PPWhoLP4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700063415; 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=b3ihm64DLhXgEo21yeb6GRZDfRI7P6/1vvxJ7ZUFSPA=; b=IoVpORLKvz7sezlZQ0C4E4wD4laewiDcriZIKlBxCOe6XNtlmo5xzrahQQvrZVZpMYL8JX 8951FQ7xrBBdHPsxq46+PEqo6grNLXDSDOOSDW7nF04Zi4UV/+Hkdx00Q/bO1/wHsUBANi e1W53HRu9m8w9EcKMZuZc7opWCaF7nI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-621-KoY37iMuPKyClFxPWlKzTA-1; Wed, 15 Nov 2023 10:50:12 -0500 X-MC-Unique: KoY37iMuPKyClFxPWlKzTA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F1A0A88D048; Wed, 15 Nov 2023 15:50:10 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4435C492BE0; Wed, 15 Nov 2023 15:50:07 +0000 (UTC) From: David Howells To: Christian Brauner Cc: David Howells , Jens Axboe , Al Viro , Linus Torvalds , Christoph Hellwig , 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: Wed, 15 Nov 2023 15:49:41 +0000 Message-ID: <20231115154946.3933808-6-dhowells@redhat.com> In-Reply-To: <20231115154946.3933808-1-dhowells@redhat.com> References: <20231115154946.3933808-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 2EEC61C000D X-Stat-Signature: nyuik8siaf1i638o9sp4itxxr8rj68j8 X-Rspam-User: X-HE-Tag: 1700063415-21045 X-HE-Meta: U2FsdGVkX1/v+x6E0dBHYwdwwooeipOACskltVh11nCZ+Olpak0jGEXusMUUdaDYXHtZzgAAzwOOID+IbyV9dcx+d1u5EEoLfEpJZrdNy2uSH/ZbUW0ZXNhDkp5i0uTvjt/MFC1PlbZADTp6cZFncdhu28DUoOkPgEXJsS0ZSzrHViubE1ulveSIgsPt/SmXQ/Pjdf3xW1M2lXRthfWnHfXV9vYVEB7t+ajeEAkTJJt4QPjuWIoi6ycZ1JD7hw+PcQ4Ed1S1X87l6vWgKaY9CYliqu+le4swuWepQWjr5a4kQrpjCHzufoZyPtXl3oa/UmydiROm+UaNckzFEi6Wdq1FY/gvzSmx0PGUxQhb35ifRARxZ8MUUjwVszc4OZAutuW/3OXt19laeS7rTP8r2Q1cUMi2YSX8+I6HGoR60ruK9nZ37rMz9bkGBI/UO631OML0twN+SlVWfhEc+jEPTtwW+Uzyo+kaHNpsebzdG3z0xvlnKyNta3gtY6R8zIbFJUKkyh/kybXa9er3LkLO5GFJ0UnDMDbAfxy47C7+1+RnpZ6xXW/i7l8ASIv3kKaCnq/LawLCS2ADDyLUj8BJvrb1wAE15AlbfQv0V1R4MlHh6/ISXkD4TiR4BsLmSdAgmu4Rg2Vf6Sx7agLfM9eSXP29rMkF6LV4ir6AXzNdid4IY4aW96adFL99TWAFgOxVKyc3GX9SMyP618G/MGG8pU97iXo/J+Mbw6Yn8ohehCyiEpSvhxgXhmww3bGVEk+B9KebYTa76SHBOSIClVE/4xV5SmywvwZkAmuU5KUFkt4CcD8FQ5TKtAmcWifhzdo6gQ1bCdURRRvnXtHaAYJl/7pRdJsSxmm3/7jMuyyFLzPHQAbp1ICs/aaLcBbDaE9FePnnjboixfEMCwkMBC+Dj64opMydnE4wZ8JnEctk8bcVwthgqQdnWN791gthn+vw8esL+/Df2BaugFLna5U xkPv8C9B jFvlrmFhjcNa+iWuzXIWkPHvF9i0tjN77TOXk12emKe+iuYIFZ3bmajo1GchyQVqrrO2QxA7Mq9nFmVvv17jRPbZw1IXF7IuI7BmwFBT4u7sS7DQqg1ou6Oq5dTP8xH2/6KISoIo20Cb5o2M1IrYALXShSldCIh2DITFeqQeatnpORnRoDyz1KEIpcsPk8JAA/PPzWNpm1rJgGvH5J3PcSipXhKbqmcF61XcW6gqm2/YBrZRqej8CaYWhF+jnOcPEY16ETAqoDTOpZ6ULYdT98TyttQQStsKktOy7oEXEHmDYhu1CSrTkAQeEbk7/AEBmz1yNph4vU6V63FVOCndj7Lcv2RoljOHyXPSfqte2iBIQvphRztyt1ru2d/Xt/p+EpfFrOr2c85RK4adJwjU8gCbodBg6uIjtmEdTx1RglE2z6ndWlGqkY8fMVsQo0WBsTiBOQYk1I57TKa0nz4FVMq/1vLo3Ljfb6Ikpt6kNUkm2J4qMqLBdzy35Lwznto1SHdDtw3cA0kyhE7I41rN6LdmsRIpcRLHgwQinHBYgaIIvFLulstTgXSG4XMVGymZjhLHCqy9LnOE1otSWlMlH9bXz6lJ47YWHA+4dwUtG9sX796xRCTXovHR3dP+yWpQA4TK2OqxjuIkj0Ypj2796PvoEchM9coo3FVrKajIOyL8+kLQdva66XSChA2Ym1jabAcrE7Gzpyfm2S5YrREol5OpXTg== 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: List-Subscribe: List-Unsubscribe: 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 d26222b7eefe..e4862dff235b 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 10917c3e1f03..f6d9e0d0685a 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 1971bfffcc03..8a2595b8ec59 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3383,6 +3383,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 aa01f6ea5a75..518f7c085923 100644 --- a/mm/util.c +++ b/mm/util.c @@ -455,6 +455,9 @@ void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) mm->get_unmapped_area = arch_get_unmapped_area; } #endif +#ifdef CONFIG_MMU +EXPORT_SYMBOL_GPL(arch_pick_mmap_layout); +#endif /** * __account_locked_vm - account locked pages to an mm's locked_vm From patchwork Wed Nov 15 15:49:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13457015 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 1FA93C072A2 for ; Wed, 15 Nov 2023 15:50:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A73278001D; Wed, 15 Nov 2023 10:50:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F9CC80018; Wed, 15 Nov 2023 10:50:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 874678001D; Wed, 15 Nov 2023 10:50:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 71AE080018 for ; Wed, 15 Nov 2023 10:50:21 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 41C991A01C9 for ; Wed, 15 Nov 2023 15:50:21 +0000 (UTC) X-FDA: 81460625442.29.01F6A65 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 8C46C4000C for ; Wed, 15 Nov 2023 15:50:19 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZmiC++lC; spf=pass (imf07.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=1700063419; a=rsa-sha256; cv=none; b=amfgqBvDqkTODRr6aSxav0LCjDkaydD9Hzl1fpJeeiMYOI5pKTzNV58HrMUMzYJCA9BAhA zXgidH8Tf93XXp0CGUsHZMvYU+Iv+xSyriZaDG5yuoXwcdvtoNe7F9X+t/j8TWMIPbvguC jYkepNyawX0B0Cd3O9VufRah1TvQKNA= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZmiC++lC; spf=pass (imf07.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=1700063419; 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=TFxve5Dd5IEFJU8CoGvE0XSLvWcZaWptbAgqC/GMxF68Y4jkG767awaK4TcIq29qk1RxWq QQ8WT7SrqQwVslHD9ME9d680AfNSFtENquQhKIa0J3Xchhxo/+HjGBE2/UEjCW1vtgZsaL Fgfs7eQIMeTJCX8/uiWX7CM8kqb+f0M= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700063418; 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=ZmiC++lCaz6CVh/ziBqXNycgJ83WkMfpCmxZOmSedRXWaGvvl1CdkI8LkkmmLXcYoZSoNX frspTvZ7aJTfucYN7d8noWX01iOFnjwtTNoZehBinTg+XiPpK8ea4V1iXEJ0vIhLz4TPu5 +tmTDZTxt5iKTBrYeJMCqaDpimPJjVw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-166-paADNiDcMD-8KlevGlnejA-1; Wed, 15 Nov 2023 10:50:15 -0500 X-MC-Unique: paADNiDcMD-8KlevGlnejA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3CC4F811E92; Wed, 15 Nov 2023 15:50:14 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D07F2166B27; Wed, 15 Nov 2023 15:50:11 +0000 (UTC) From: David Howells To: Christian Brauner Cc: David Howells , Jens Axboe , Al Viro , Linus Torvalds , Christoph Hellwig , 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: Wed, 15 Nov 2023 15:49:42 +0000 Message-ID: <20231115154946.3933808-7-dhowells@redhat.com> In-Reply-To: <20231115154946.3933808-1-dhowells@redhat.com> References: <20231115154946.3933808-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 8C46C4000C X-Stat-Signature: he5opozf7d6zqw59ftcsod5cjcg78jmb X-Rspam-User: X-HE-Tag: 1700063419-427478 X-HE-Meta: U2FsdGVkX18ajLzcub2Zw3/vGQvh+U7/Olsgyv8JlBx/SUVnYkBhqV17mLQwiEScMHugU9AvNSD/0wF/SXrHinDs5t2MFxf+gLWgodRoMptSZKSz9SHMcrduC3mvgtLFrhCVQP5W3ZLwocHIWBskDmVgfUP9rwhbVqTQCRgedeFjmg2qT1sffgEXW/Lg2iIO7SVLVB9IuHDEb4XRUuuJfl5LJhelRwgemxiW6GQ/SFjOB1nlWdo0ZXcQ1eyRzDFv39BaQVgCnghDMc3nUqxJuBN73yGCG+gyp8/grvI32gWU+aqEPYlDItuzhys0RCuJXB1EVd8GYFCLi41jfGqjIGL7JGqJ/LWgEPJ7v3HEAQkeLOpUjqSKIu1Z+BcCXPzK5xTtzHR++k7h0RBKaOvXJKtAsxJbjQODXaRLOc4K8oZNPoHm/0gAuaUaFp6ed5WKb4zJFedHdZUp9s1Qs0AG3uh/xfcu78ExbYS9FZ9TZwsOKPfH7rBPFT54iSZzSGyG0C1/S341QrXVQ98P8dFM7srAk0A1agVQv7WQkK6XmoAR61MWE1PU/3cf0B6G8wxNs9ZuzTDpXGGa1TBtxBRz4oWdEfVur33aYLlAFHE6AQ8iBusOeodioWKOCU7SVpKOVUCCaIfP0EOdu/InoQdwxlo8EwHAswQXacBZpyQlazbheQFpUFoSuczBAMX1VtJ2QhM6xnA2TfOzTcJTRxbqWQ0TzcYccHskR6lMbn/l1SBkGqX/MnKcAeVVD2XMqlOxIEh75BN9QqV9TyW9Dr44ZnBJgcgNGVvI3IPYrOD3R2Fc2Q9/sJHoxPlDRnY3m5iYZmWX1SxPinAi618a7SusyRmy4XFn/d+Fwb36I3fl9jyWZ2Y4bVsKlEUh9kcSZhCJMQNh+8qzKiZJjhw+G6aa3PVQg8OLoTfYPuky5zo9XKrOzHkAs6GpnnHtHrOQ54mKdKmw8UGMtbxyl6o4ol6 dQKcbJlK wiEkgWhNP9BdyjDOOhZSHUtZITpUyG+8ujPGoa7T4Z5/7lgO4sQ88HdIQnzW1hKH8Gi3frc63aQU0fwzNx/CMIxTnep91HnW6w2GyThhuneWSYiYPWtGzL21PCri37eAI4tPDpkb6CqDJ2CeurYqevJsrawRdfvVUL6CE4qy3y83fwfyPCNwr4FWJX21I6+f81N42dahjzsR1yToqHFGgJz/0tAWWpa1LR4GHPa0/ZpZIvzGSscYYLkea1ETWVr04Mr+ZjMjcrvDAEpSejNyOBtWF630eykxXO91dz/sKF7LWtiu204cNdT6JULUJdEUM+0M4gogVnPqljbc7p7PA7zZZLrrbYWC+kGxbgANuAcWNdwv3JGcgXGlsJZX2I1hZyAZNr7jA5Xtphu32MQ8HxU87Nm5q+u28iuMfUgKPC7ybP4/EiDBOzI1hQNoQYPv0MjQeO7vyZUHDtgCH9znoRHjD4TOUwWeCndx/DTuhe+ilNAbTtO2ng2fnwVid3ixs/vIu6F4UldszDKBjC96/XrqGuGXbXRZGDLffFNwRowPMn25Ed2SwHpKYhYwjP2c7Fc8KACkxNmLnuBcqsceRUGSA08idBHF1Vkcq2Fw/VsP+sftP9Cc4JbtMOA== 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: List-Subscribe: List-Unsubscribe: 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 Wed Nov 15 15:49:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13457016 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 4E81EC2BB3F for ; Wed, 15 Nov 2023 15:50:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D09A28001E; Wed, 15 Nov 2023 10:50:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CB8D680018; Wed, 15 Nov 2023 10:50:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B324E8001E; Wed, 15 Nov 2023 10:50:27 -0500 (EST) 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 9DBB080018 for ; Wed, 15 Nov 2023 10:50:27 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6B2771CAC74 for ; Wed, 15 Nov 2023 15:50:27 +0000 (UTC) X-FDA: 81460625694.29.BB58ABC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf20.hostedemail.com (Postfix) with ESMTP id B842D1C0006 for ; Wed, 15 Nov 2023 15:50:25 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AK+gtyqp; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf20.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=1700063425; 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=i8SNLCJnWve3XAXTcZ0gDSB/gcBLs1ow1A10a8Q+CT7/aYmVDc1dW4ucOahDjYfFqsWy/L GJuT3QolAT/EExgCQdK6ZicBJCoXMMUgILTzIPSXXYj7vlBgMt2myToCzqeg7DE/tLwOav r0+A6VzConf8+hvnonRHp9I0IVG3IP4= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AK+gtyqp; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf20.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=1700063425; a=rsa-sha256; cv=none; b=5hAOyPc5urrG4yCtYJO9uwLwjF48c2ZncVioBSGu7ex4ARCGyjuEY56sRwF1gPCFmXoKco +HFGROh2wCD/Be0R/Aov9vAxWJHtQEv1uUB33qfztGKpJem/hsJDo1ZZzU11dWK2bUNUWS +Z80T8btbeGdvSx1Tw/BncNoX9/9wgg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700063425; 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=AK+gtyqp/CM+y44wSJQOBdEXebFWvF3cHOmLgElYS2O5hASfCjqfACnDxc0b4D3fpXXNjf rHIJhbA++Ii7v4f0vfTyTzz/AlkcCLdqK35NQl5uZrDe3qNsPF5VrnsG76PSaDk6BLW+8Z h2zGEYNNj9plYsU6SkWOniOsIsWCZ6Y= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-632-aUOqZDu2NJavfuyT2sjYzQ-1; Wed, 15 Nov 2023 10:50:19 -0500 X-MC-Unique: aUOqZDu2NJavfuyT2sjYzQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AB4C33C000B4; Wed, 15 Nov 2023 15:50:17 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 040352166B27; Wed, 15 Nov 2023 15:50:14 +0000 (UTC) From: David Howells To: Christian Brauner Cc: David Howells , Jens Axboe , Al Viro , Linus Torvalds , Christoph Hellwig , 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: Wed, 15 Nov 2023 15:49:43 +0000 Message-ID: <20231115154946.3933808-8-dhowells@redhat.com> In-Reply-To: <20231115154946.3933808-1-dhowells@redhat.com> References: <20231115154946.3933808-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Rspamd-Queue-Id: B842D1C0006 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: d34zihk53hwioqpittfgbbr4zpfdjk3x X-HE-Tag: 1700063425-623027 X-HE-Meta: U2FsdGVkX1/Pu6weaoJMnW+v+aD4txBA3FQkHtr0BHkSWNbA27XkIZJNoGupjZU9GDB+B+Bsghda5bL4oWIZYpZsSoZ3m0SiBECIY1vAbfqFvNQMk0+6bUbZ39WydRRWog2ZRlAa21KQE6Gx2g+ILvUlyCPCGhRv6qoyYUeBSGP/9rI5FaetKaVUrwGt+/5F1jl9Ujv0US0vY54jZSCPXLd7wpDQggNzzayW46KAhMN4KTWd94JjxIDPcYY8LSe3JgGtPI4qQ9XorlEM37zxNjjim3QVR8IhwdYavxkCMc7C2XWKMUjC+FCXXAmCfvJYY1brROfuRSE2QCUUtjeoEr7GcsU9/+IFo4aZ9uCxEUGmvEk9/GFfCrYQ7jfs3aXqo+FEwTigCw5Rkc/jbFRJMxfxCjb/2I1ahOZEZJGmbmibI5zE9FGu5cVgfYR6TSd+BfCBV87CcT1Msq5dzoXAaF/auJH9+JYTiM16WJXIEds+NetkpsJMrl6y1n4Dzxoa1nDIdC9VoOI3SIx6jaiaQC4JwiYXHPpcbLc2FcPycBqSZzloBpRJjA8Cur/w0WcQaA2OhnsSRNH9GicNP1bvuJ9eaODS4lOBBP/vPLGEbkfO2haRKww66eCvep/wn29V5IeW3eu2O88XH187x4O/49syf6H1yalHVel2uVgTb9rNT+gZMD9QlKnZiILBo31PgQFCq1nZXesz6tFQulXQBmMskoH0rHtEI+xfOPSvGxLP3IHWNkNAJdOfD6DTpOFde8MpByKMxJnI9+Cmxl+Cg0IiqpOuM8QeCGTVLXF9IuAR5YfGJ86z4DmkrHXcMG//kQkqcO7/CKCRU4Cc8bsi3r9f0r0B38igcJbwH1wt2Omk80XGwP30uK02UMEVXdrk7GvYBuMqWCPIeRfDBx3AL9/G/OVEysn+rrciRpw+Li7a3ww/CmsnGVtBik3yg+a89ZwdpXJaFDk5JvVNTI4 pyHMb4K8 EC9/Eoz602FM8WxiSpqAdlm+lx8duifv5IJ6gTg7Bn0dAZ26wl4FHrBPKWa2Gdel/55Feb0bvqME3Y8cnjCSIQYCgweWk5CbUjXYlUytJNV0e6gEtLL2YQwu0SyGZpRtpOvt5ciarcI1QR8e93f8f4beqGiE/imPbf0VP7moOR8q1ps2uC8FSID2Pit9s+b2BzvcLflSI6Q3nHCpOJjcYtoMxk0puFcUAmkbgKC86YW+y7QS3yvaDxsuNdcXNGmpr2pOshHEfjhOlgSTg6EmW40dNxinmmP5LxPy3pOgfvGUyOIRv1fc/J+RscinBNY+rFhk00OOwucW9Ja1CT1lgKYfyuCIkwQDIHQ0EjY7Ndzpe+t7Yebb5/dRA7qUbyKY/Ypdfcfk8kWcbgfa+spolxWRDzjvWxDz4rV5jjpi1qb0ri25tV6rZJaZAohsyX9xR1wZdvH8elbK+kdVnVmNPyGZcJ0bGll/IiO4kT7f/O6L75ZOHMrwQXrX8hZHijndtcb10jbbTh8q2GG9Um3Dl3mUVbHlj+Z3TF4UvaNtZI1O1pzJQAxqmpSkebbOMpP13NksF60BZwHq7w5D7afUBN/s8pHkmbcJuGYUqsnT3Ut7IfrFOpde6qdyi6Q== 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: List-Subscribe: List-Unsubscribe: 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 Wed Nov 15 15:49:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13457017 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 3FFD0C54FB9 for ; Wed, 15 Nov 2023 15:50:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 850DB8001F; Wed, 15 Nov 2023 10:50:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7AF6880018; Wed, 15 Nov 2023 10:50:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5DE6A8001F; Wed, 15 Nov 2023 10:50:29 -0500 (EST) 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 4AE0380018 for ; Wed, 15 Nov 2023 10:50:29 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 00E90404F1 for ; Wed, 15 Nov 2023 15:50:28 +0000 (UTC) X-FDA: 81460625778.15.C085ECE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf21.hostedemail.com (Postfix) with ESMTP id 3455C1C0017 for ; Wed, 15 Nov 2023 15:50:26 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eP9G4ntn; spf=pass (imf21.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=1700063427; 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=pcJzwlm43Z+8jvSucwj3pwrX/bfKMb5edY5bM5xS86BGUSrDyJhZ74oNFy/sMJJyHS9qLP H7WO/aEy2FJaJIqNKb7aVGV6zMbPMVdQ6EsPUEuC/V0dEuHW5Gvbkf3se1NbIRLSlMnHJt CuT7fcisJQntPuUk9knTOoZiPSfoDlM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700063427; a=rsa-sha256; cv=none; b=HXtO+/i2f0FlHWZuseVmK5rJ8911chYz+egP2/ZN6Aq2ps5G+ZqhOITvQ14qoFEjhEN4vP lAlu+Js8F46Z8n6qaEncx1vtC7rQfMTcX83mpSjdcPNnuoW/lV6xzTA7ExmRSdq2A+84aW zLqUY1X114n+ZcW+KaOJ1eYkQJ89ozY= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eP9G4ntn; spf=pass (imf21.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=1700063426; 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=eP9G4ntnT1QWScbZU/njXxc/bytFl46AS/AlMvI2L/CP8MwXfOQH9ljLJXaB5FLBOsV7om oaNZBBVMsuDH/aAoqejpe9TWPwEpMfa/Rj8GfBlDTRxaAZEI1vPH/1ClqGn71G3pa2e0yU 95ptXZqPXpwgyQ9v6OOJxRz7IkWBEA0= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-9oNthIjAOCex8BE_jP80JQ-1; Wed, 15 Nov 2023 10:50:23 -0500 X-MC-Unique: 9oNthIjAOCex8BE_jP80JQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F270038143B7; Wed, 15 Nov 2023 15:50:21 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76E1240C6EB9; Wed, 15 Nov 2023 15:50:18 +0000 (UTC) From: David Howells To: Christian Brauner Cc: David Howells , Jens Axboe , Al Viro , Linus Torvalds , Christoph Hellwig , 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: Wed, 15 Nov 2023 15:49:44 +0000 Message-ID: <20231115154946.3933808-9-dhowells@redhat.com> In-Reply-To: <20231115154946.3933808-1-dhowells@redhat.com> References: <20231115154946.3933808-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspamd-Queue-Id: 3455C1C0017 X-Rspam-User: X-Stat-Signature: 4yabjf19ftkuza4u8796dwd8jm1839hu X-Rspamd-Server: rspam03 X-HE-Tag: 1700063426-660110 X-HE-Meta: U2FsdGVkX197eTJfJE1QpsF2hoC15EngOfYjX5lN9oMAJtSy18F17IMMbpWQBdBceDPWrAAxsDWzh0O2TX/Q3WcDx/xGhQ7wm0f9vXtllrEYoGuWy2KFl7I+bdC5n5XBIR5rYQOC03dBdVQP/yJgT8rxqdVy8zGIqsb9TORW0de1BK/ELMXwfNa67JsUnxVXcYqzsUuLUE3bjpECUNgVwFQjs2biH6bk0MwIdzNKJOyRuUnafuIPcqrU2k5ZlDTzMmr0b7PEglkHjs30VUsMZOnV3iWQB3UTD8GYSf7wNovVcBNDCUpS4all9rsWdRAglTLhJgz8ua6Bm4F0faKTBowJQZ57QXMVcp6yH0oGhSn0pHkhkdGOg0e9HiJt1uEfNvOsnkJb7TAM5MgyN9oE1qWrcpsTo728Y9cEsycRDZC6Ca/g6GuD85dIvcmaW4G1dfkDzHQGyfEoIXSQ8QyxbCFJcTM5C4TfQa4pg/Xy1zhuVyrPYme+/55iN82gQNTbJfDnXj9dFr2arB78IAcA8Wt83uOCjAdN5w0wGNwUZUfPeaZ357D6Jo6fnECiZXOKWFSoMwxMWyuEc1PYIv9Soo9z8ExJgeGNJ5V8B5kx/2OYCGf0pSr78oz73wYx65aU+yxZAxjBOXqrw9iXjlB4P9G+ONc0+gauNZlMMc4cUsFJDnv7bn6rwpTlAbdViGQo6lanXVXgmgoD358387OxDft50xaL72etxb/idnsqWmU5fPnvQXY6Bia1Bc1PW6w6x1aq1is5k0gDLm1UJUHbQrDy3kPabNiKbgH/rydV+oVQ259TXKzZilE6KHahzpGvMormA0144/R9cZpe6kXqXpHhmYae1jGqmTYlwrG89+1vU78PcVni0FLXEASaqBwIhlnC5higrTrBd48j3SLXLm8eNTQXDyIw53BoAeaqjRXSah8OH1E3QrbHMuK2A0L9+cXypANStWZiwn9an64 fHuV6QaT B2yfq+eaSJePXdyGtHUV6NU6kkMaIwSX9iATLaIHYvMMuCsQg6LjRexxPf8JLwyxdv6CPJESpz2l3COlRQPAbkb4DG/qhT1jAFMlA8P/KPx8c5GFUThLKGqLtYc3hvCGGm7/T9XlXYgqH9WdmCYsoG5v6DwAYaILhYRlBcok7hC2IMI8o80pVe3/lfRkwxtyIc/NaDFl0e97gal51nLSik+UGNWisKavSwysR0lsW2arJJEzi7R2mRvivowu71m7jhZoWyrD/eukttd9vkWiLE3nv19oOSxzGx6kVjwqYGQO4U9xcAsoIicmh+ZxjCrbDCthYsdRWc+xxVAGpA9UChh/g9OZ8s2qRL6JuHixxOvXkobDLCx0CD4Y1hRa+057Z5rXPaTm2Zc3mFn6KmZoBVONfumG5lPSQDZKT+bSRbF7NJeyrBPATc3r3v0ICvfzU6FND5xh4LSG8MoDPDAoq0ZVqqbtXJIxUZdoQF2hIh5MQ9ZTKXhZIF0WRxigUcOXhpiQ7 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: List-Subscribe: List-Unsubscribe: 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 Wed Nov 15 15:49:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13457018 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 60D2DC2BB3F for ; Wed, 15 Nov 2023 15:50:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB75D80020; Wed, 15 Nov 2023 10:50:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E667C80018; Wed, 15 Nov 2023 10:50:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE22480020; Wed, 15 Nov 2023 10:50:37 -0500 (EST) 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 BAF2680018 for ; Wed, 15 Nov 2023 10:50:37 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9308FA03AF for ; Wed, 15 Nov 2023 15:50:37 +0000 (UTC) X-FDA: 81460626114.23.D31D3C5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf30.hostedemail.com (Postfix) with ESMTP id CEEAF80019 for ; Wed, 15 Nov 2023 15:50:35 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bbukalrK; spf=pass (imf30.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700063435; 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=3z5DUvh+zyWIo6MWm938gLltsTPa1EXm414PCvDdlghgqrx0vvokcl1YX6uR3YKDmuMvx4 MS6xQ4Mufx3fN/DU7F15O4k9Gv1dG8BBlNiheClouT2eOiiD1RkKbgmc+s6Jf0BwyfOqwq jvHJTmz7FtaB+WFzkMJhjqw4E15HSbY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700063435; a=rsa-sha256; cv=none; b=MGvwNcRTCC9mVjqjXfe2q15PXi9qLMI/yUbab3NNlol/CigMloITCMkbKF0UxNcxUuhSbv dNjAoPUTubkO4GToZCpRF2WqJXz4eqxeRK18PspcFCVnitx+VFXc3G4HbLxbSoLTjnqzih gFQASwP4fEQIRqemwgqXz5Gf5Kphvvs= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bbukalrK; spf=pass (imf30.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700063435; 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=bbukalrKgaObdYb28DpVd6Cnc9pff7wWSha42Xqb7mLFkWgn3biTP38UnA07nXzs5O75Ft G9xtyPJv7fFTFSqo5d36uY8jOYpR76pp1yXsgiEirvyoi/vJOucuX/Xt1VpnPqq0bikB9o ym33jrMv7lJ/8HfEI+4Oj4eRxst8wII= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-417-p2AxTLinOM6LKeQW9-98gg-1; Wed, 15 Nov 2023 10:50:27 -0500 X-MC-Unique: p2AxTLinOM6LKeQW9-98gg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E13468058EE; Wed, 15 Nov 2023 15:50:26 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 177271121306; Wed, 15 Nov 2023 15:50:22 +0000 (UTC) From: David Howells To: Christian Brauner Cc: David Howells , Jens Axboe , Al Viro , Linus Torvalds , Christoph Hellwig , 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: Wed, 15 Nov 2023 15:49:45 +0000 Message-ID: <20231115154946.3933808-10-dhowells@redhat.com> In-Reply-To: <20231115154946.3933808-1-dhowells@redhat.com> References: <20231115154946.3933808-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Rspamd-Queue-Id: CEEAF80019 X-Rspam-User: X-Stat-Signature: qcd5bz96niu6a5cgsb6i6o9e3ha1jwhz X-Rspamd-Server: rspam03 X-HE-Tag: 1700063435-865771 X-HE-Meta: U2FsdGVkX1/wBse3iRVMSNMiOs+LaCXA7qre7s9q/DDvIP3xsYCad0Y2DSustqS5w4gdJ7cHUpMbtZcRh/YwA2KGVIZJQ4VxDPDo71JKDYAu77a0VUxyFCZO/kN559Z8snAFpOcZHNHMGlSMw77WlU2ilV2P0oRP2JPxUOVJLKCwKdvDZl/NjDzCdbWLPmIX3n9A+797K7vsmp6lVhkASTcI5HiH5BppfwMlCyKG10472OOW5Z8bU5UtzBk8bRJC5uh6cKW2UP1Rphx4I1sRZZmEJu9F/CjIe6M6Yc3ND+1396xeKuOVlf0wrqNFFWay6tAucLTeungEroeXpGsDUcPuMkZBzrXrfrXPMJ7WYgqPuZASKpxcY4y8Bo9cdVIkqDzL8KCRs2ivj77cED4K04zCuyZrVc5wZNsG+ZJewl57IIVqA1s3w1wXtnrYP3GCjg5bCFkBc+SM85+63VgaFlnMrTibA2DnEG2i/Un5d7SKfWv3Ht1zWWzSYV8QzbxUWxmFt94Kd3+asAcNuGC3yMHFQSwTIJ0FM6Dvtd46oy/ENe8mxcrQ8j077Zq+r3Kx2U1gtEeRx6wuP4o+G13hMLWVCYPj+4E3O5+9Y2zgArV4KkhkohmG0vKqFbzJfNLQ6lx52gTM5gGWicIyXZ9+xB0zUvGYdJULxkJrSvQwFHFEBUdcx8S7y6PNycsaiOEkmmrwMKuZpyJkMKAS7by1MadT7mefkt4J+D7AgHDxkilsYyaqWzHia8CND9Xhu59HZsxv67hkqOEz2AjNg7xZRiwKUvdDKKdcQp9Urm+OCdKRs65DT6JSFdPw87FJsoz27hk+obss5Jbi8mFnx5/NGzrnkUE0EgJRGAgIyf7s2QKMhgb7B6urHrbTXB/lGIjlLBhDtmUlTNskqrE49US48ul8B2fLkEa7oMcLCLrl2DFf7KUV5wFXb8F10YSFlUII3aPbAvMnfLbck7M2OeU 8sCoPT/g 2uy3XTjOrzVa9RYKG57V0+iLUKm27IxunQCZbquarb1botGfo/Vc+WEXkxwK2JapKWTWMVWjpwvePOtp6r126DnIn4B7cWu9+K9sVE5SAIsAd9XPu2NmqwVTCm4oQnrRc/9i/EePcLkpqYEEThyjZkd8gaycFzQKusLMJSD4uIkpgWRuvEj3eaCRgrWAfv0BmGzkC5R5Bf4zJETPlPw8hq5odBbOPcuXFHYedljVIGwn15qlLRq46L5knsreViovx8duQ4h9NpSxDR3Gn5yhHJunRC/W32gJ54YE72M7S0vElWelmGEbXwCfgFSlQQ1JcvYCYK+1y7sHBH9OfewAnBwsTSB1z1NIkPO5DhjFmSZc1ae2/x2dOZIQYyv24hBcr0HB1bVJz6dN1Vqe4ufeQ2KUbEgF34MHQVeTTRywXbcCPDZdifoW/mEtFEeRy6TD0G+ULiLGh2Gq2vHRsLcR75uAWgqBu4DntI3ReNQbJRpFFKt3pBe641/Y4A93Ara5oCHi3 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: List-Subscribe: List-Unsubscribe: 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 Wed Nov 15 15:49:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13457019 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 8356DC2BB3F for ; Wed, 15 Nov 2023 15:50:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1BE4280021; Wed, 15 Nov 2023 10:50:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 16F3D80018; Wed, 15 Nov 2023 10:50:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F2A2D80021; Wed, 15 Nov 2023 10:50:41 -0500 (EST) 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 DF4D180018 for ; Wed, 15 Nov 2023 10:50:41 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7FAAE40981 for ; Wed, 15 Nov 2023 15:50:41 +0000 (UTC) X-FDA: 81460626282.15.7FC871E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf14.hostedemail.com (Postfix) with ESMTP id CF4A6100010 for ; Wed, 15 Nov 2023 15:50:39 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aXQj7MRS; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700063439; 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=HF/7tTXw9x6FBeWdSv6dRg1xsOkc8k6GdK0ECGO2hunCBy6tw69rU0ibSAZy1oI1gVe5Tr rs0b0+1gfFUBAdoppZ0B35xSxSnCNaN4lFN/AFrwIfCxRszDAJCmFOi0339q62HuhKE3OV YesJa8QNJqxmG5pchHXBofJAVD1j2Yw= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aXQj7MRS; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700063439; a=rsa-sha256; cv=none; b=yK6SEsccqxYCRzqepTNoaqCxNAubRYFntCNsxsCyKEQ97+1zdFXrJVNSiIrLG8EXRHZ5HM kgpXDx+PKyHd5UI/yhguyw+vRCFsOe06fDY81BJU7sMyeAMSmZVl4x8vHEo8fH/JxbokXp fZ4hvTw0ltCLUD48ELeMTcFEkBaMAkk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700063439; 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=aXQj7MRS0Lhen+Yw0VpCMHR1vEmPDgoPZ9h8XvQNKWPQGY7idwAtVIu058yG3kIJfCyPIy WvgxGPZRA0ajqdr9C2RlYRkOIzqpIYzqdphTDI7OEg5JLqSzMPeTttTPLGeZ71R2tx4gKx VTfqynem/hFC2AihJzki0Asf2LMcG+Y= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-67-_sSUMIArNcOe3p2xkegZtQ-1; Wed, 15 Nov 2023 10:50:33 -0500 X-MC-Unique: _sSUMIArNcOe3p2xkegZtQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3E6A23C000BB; Wed, 15 Nov 2023 15:50:32 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 043102166B27; Wed, 15 Nov 2023 15:50:27 +0000 (UTC) From: David Howells To: Christian Brauner Cc: David Howells , Jens Axboe , Al Viro , Linus Torvalds , Christoph Hellwig , 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: Wed, 15 Nov 2023 15:49:46 +0000 Message-ID: <20231115154946.3933808-11-dhowells@redhat.com> In-Reply-To: <20231115154946.3933808-1-dhowells@redhat.com> References: <20231115154946.3933808-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Rspamd-Queue-Id: CF4A6100010 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: wsx4ydo184x9bt4773otajetrjjcbi91 X-HE-Tag: 1700063439-715681 X-HE-Meta: U2FsdGVkX18tGDA9OEI+qQA+RotC6bsl+KRWA+wQM+VK3q18afxJBodiZ6YriVzP5mdoMlxQJgdFGSFAULPhvsGI0eLEPNbLqGEjlv6G6Hb9LkKryMk9bBAie7XDCNW3/TWOLXU7v8ELtAwxGKLi8pqycs0oGXLInWay0lajdx2PlmJdDAK+EHpGzjv/jSziDeXCYsJ4FluBf1tGC2xaKntK4CrOneyzAOf1tJxdDEvSM/OH13yhJrKtrv/I3veLkIo/bjSQQ8M706lxtx4FMQALEULAnZzwNl3c4AVoDNsUGkF53M80mmRf4nnMQzkgTli2Amyko8vCFQEwbmBKRJHbY2ZZNZFc5fB3bY8rTofiXrqoJFc8CcpfkjJ44giC/x5sx6k1anywTIPfNUUNhDy2lARm2rx5BQvkMo8FgZBX68ke7kqa8bdrPwKz8ktGMygrTMwG0ZHWhW/69tF+jWo0AhiZlPhVKZf7pNN66zPyVOy8z++Tqw/UrhFx3zbBoAVYPMeOgLeb4qchp+GaKg4F84g0APEXNZlEqW2+y+0AN5l1jKyUZkewZY91M0sEDNtK9Eje45t4N9sSYmOPAz1AP8BBRtJwE99EpdtOti2DwSgWZIv9i3U9ScY4uoWcSREDKaPRsCI8zoIE2cKcqhIcWZC8EyKZSnkgAlShL9Ii3BetZX7i9goKyjUOmzOqhk8oJt5v8vJJdQZqzPpO87sU5t33ionYwnkgd7p5/B/LMEXfb6iVTCE3vbJVEiVAgFJdSEwxNYq1IhZGP6zZVh4B8hxXHq/TkCHo265ub3R3N7gt92V/1pC4bu1s2Gzpfp4lsZwdGea2BSmOchOrBjgc4EtzozoSIliufm50sbO3K4OrGXZWf7MN/l9/K4j49rePRjCg8FgDDoD/nB8vLRigb3TM3bSr+ENMsQjC3UZ95ujo3Oee9L7STn3PsiviDaPImiybGEwODtf+9F+ Tzf3LD1N UV0UfD5KwnrCBGgFbRohQtt85BP2x7PqNtgcym3PD0wi0Ng3nHumyIWtgYiW4Y5O9powVgZm7NMl7ALK2dm6QNa0fNO0aw5eExf9xGsP6nxpbX1KS75C7nb0ADbtWLLrnSYzlmGO3psm94G34GNAR9vTmK3SHZlQ3jZD8Qw1mNm7wSES51pMk6dJr2gZctYDLKQorRSmNvTNtXz6FKtJtMI4zCttSFJ88xyGxvi/+njBqi9hTPLx01HzVGw1F54kpePQXB3xQHPNn/BY2o7c6sncs9pxJ2UPpt4nFuEhPCKQ3zvKphumX51DYpOczjEnRaabiSBaEgj79vpZQ0vAMACgwU/8EUeFbHmgQ88MVCR8jSsUBW50j5Jf1+6UJOsYN7wS809xravTbHEKsJl3sam6kcQwytzyyjgWflUzjLzjGlZxFt8gyFz9yta/iLHLvG3xHgJ+n1Oemf66NKYW2b7NUvw/t1t6r5Ms2SeaQaV914m4uV5+sEOt62E+4auU9k9Sj7esMpatxwVn5glX1s7hjNYJ00ZJDX3sSiJ4rhM+MS8LJiYoESOcU0sbylL9b4chEAQMQKguBq0dcrZLOcQ57LjLbxHut+BCa8TATopKVh+zQ/32rxdfsRg== 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: List-Subscribe: List-Unsubscribe: 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),