From patchwork Tue Nov 21 17:16:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13463396 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 D0E50C61D90 for ; Tue, 21 Nov 2023 17:17:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A63EE6B04CB; Tue, 21 Nov 2023 12:16:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A13916B04CC; Tue, 21 Nov 2023 12:16:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 88DD96B04CD; Tue, 21 Nov 2023 12:16:59 -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 6DBF86B04CB for ; Tue, 21 Nov 2023 12:16:59 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4A5D580A8E for ; Tue, 21 Nov 2023 17:16:59 +0000 (UTC) X-FDA: 81482616558.02.170B74A Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf16.hostedemail.com (Postfix) with ESMTP id 497DB180009 for ; Tue, 21 Nov 2023 17:16:57 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=RmGgNM8w; spf=pass (imf16.hostedemail.com: domain of 3COZcZQYKCHkprobkYdlldib.Zljifkru-jjhsXZh.lod@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3COZcZQYKCHkprobkYdlldib.Zljifkru-jjhsXZh.lod@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700587017; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=16WWsVx2wninDVgD360hRJytZJiRJbLfp5hnTHjwaT4=; b=j3t0CHVgzTw1ZEngLpaT/TVEBWiSfP0OsvRJs9IBqwQ/P3phdRAlnzaCpI/nHpWyB7JpDD qJGNS6JuqKpmP2+ofHcrezIXfUajAWeIf9iFTCoeTcVEuES66ziq8fRqwx+21UF301JNym 4wilVcHTe2bxX10zRVhm90xkqBIAiag= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700587017; a=rsa-sha256; cv=none; b=so1D4vFoQd8HtqPTTxTiXxA4PXws3iFDB/FvK5NapJ8+f8PucgmT2i2J8pp87h11LDXv9z vk43uTVOQXCHdMnIe5GyncnDnBwEjIjOIqX4GooepoSqkQ4mWU3NbhrY0y/RRTh3YRpprc tGalfkg8bi6N7h2watvyzQ/Sc4xlUQA= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=RmGgNM8w; spf=pass (imf16.hostedemail.com: domain of 3COZcZQYKCHkprobkYdlldib.Zljifkru-jjhsXZh.lod@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3COZcZQYKCHkprobkYdlldib.Zljifkru-jjhsXZh.lod@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5ca713d53f3so45739987b3.1 for ; Tue, 21 Nov 2023 09:16:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700587016; x=1701191816; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=16WWsVx2wninDVgD360hRJytZJiRJbLfp5hnTHjwaT4=; b=RmGgNM8wlicvAoYi5XSOIZk1M7v8m7s+xcYWAWbfvCjsklseDfNgw8Y7P2k3fGKoKE w5P2Ky7Z6vRjJyWgoaLQ6M16QriMpdJPZyc+rxEzyQUATJWnaUyO5pvTKGoF/OavCnIf 8lcxeNcFeAhLIzeEChI8gGJTf3pN2Navjhj8lZALCVZKWlPUgpGPRAOttS2hM4tBWpRV FV5W6973mDrjU6eyss82TuYh8mqyI2YB2K52cJCoiyoT1sqcwC86jeEmELmzDfUcmwkA 7TBM8TtsG8TLYXcjh6gPXfSSGtsWvbiRa/4GrVFEuyQ62nJYprZ8Y8sGxabh6ca5zqy2 b6+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700587016; x=1701191816; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=16WWsVx2wninDVgD360hRJytZJiRJbLfp5hnTHjwaT4=; b=BNKx4p1BUMyhUTSXLbA+e1abvFpmE6uXBWtebVMZMu9ANFsAyTwn1jIfn1BvmRXPom vFpDy8R1ER2Zzbq36UwOf8PuOYVqs7zEhqW7jni78bj3Rs0oKWjYbC4B1R4Gc7o7XqRc DlhYZCVAWsRFtyrdcxOHgcJpgsWeA+1y3lJ0qn/lz/intAEYKJh10RxYhjzUwqOtKwcc EkzL1py78sVMCcq44w/iqWV62G83RxYwX4kHRTekup4Bf2qWwdX5JqyHK03IEFsi7Kxv RAL/GS8878KHLN+uzqgnnMn0BGogi8s26iaCDfqQC5WWM1+piThbfHiazOrn+rDtmVm5 oINw== X-Gm-Message-State: AOJu0Yyo+6Z4terRw4OE9E2DFijto3ruA4tR9h80RDMqYWoLqt4yopGZ nlMFbfNFmM9WlRxK8dX1JSz5V9eCqKE= X-Google-Smtp-Source: AGHT+IEDzZp+znMIvLmLUboaHGb6wcOjpm4sLpEi36+gWsJpIjPPrJpEev3RGtNgfOw04VbiAOuwWaVIAJQ= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:2045:f6d2:f01d:3fff]) (user=surenb job=sendgmr) by 2002:a05:6902:110:b0:d9a:cbf9:1c8d with SMTP id o16-20020a056902011000b00d9acbf91c8dmr324632ybh.12.1700587016415; Tue, 21 Nov 2023 09:16:56 -0800 (PST) Date: Tue, 21 Nov 2023 09:16:37 -0800 In-Reply-To: <20231121171643.3719880-1-surenb@google.com> Mime-Version: 1.0 References: <20231121171643.3719880-1-surenb@google.com> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Message-ID: <20231121171643.3719880-5-surenb@google.com> Subject: [PATCH v5 4/5] selftests/mm: add uffd_test_case_ops to allow test case-specific operations From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: viro@zeniv.linux.org.uk, brauner@kernel.org, shuah@kernel.org, aarcange@redhat.com, lokeshgidra@google.com, peterx@redhat.com, david@redhat.com, hughd@google.com, mhocko@suse.com, axelrasmussen@google.com, rppt@kernel.org, willy@infradead.org, Liam.Howlett@oracle.com, jannh@google.com, zhangpeng362@huawei.com, bgeffon@google.com, kaleshsingh@google.com, ngeoffray@google.com, jdduke@google.com, surenb@google.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-team@android.com X-Rspamd-Queue-Id: 497DB180009 X-Rspam-User: X-Stat-Signature: qa9ah9abyddr6u11rpkopk9z3acqiitf X-Rspamd-Server: rspam03 X-HE-Tag: 1700587017-580909 X-HE-Meta: U2FsdGVkX18fiSpUGn2IEYLDTHX8YWyPfUh5SnwugHFFJAn+NC3kSEl8usbh8kFEm8k/dqb4ZM2A307inLVjQmM/f+Ud9HbXS72aUD0pxaLhlnipaEMDzl3VL8rI8eAmZo2h/gtesoVAIxclzxHI9Aihli4h3v+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DpLFPW0xK/UNjp6cdNSi6fDydH4jM7re02KdiItBzm54IKwzXWvuUjMrgiyaNnF9gSMAm9uFYuMEknFJDyf4vlTdix5DVLDJk4NXWqkkq2XtvdYsViNVJDqgIL4r+DPSlmb15hVMu+YqyRGRQt6OBEGq1650JHCLUZGnVA5rwW2BD7j2I9o5uVqsFggOm3fpV/zFSnlc0s2gElQ2PW/DebZO9OM02R3y3ZDa68Vwm680PfF3tQF9/IrJXY70rHsdiG/9xRp3+Hzskz5qxgkXLnPCYovwK9Xm01ckpBC07XFsFZKTYhIHMFfcjElnCWLSFj/GWtKKBF8T1CsSEb8MmD6TxGaIFe3xuQVt5KxF6cGkL/wdO4MPKy0ds45zswUUWy0QySgSASt6qY+oW7IHYR7MljImfKGgrfFmW42eucybrQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000014, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Currently each test can specify unique operations using uffd_test_ops, however these operations are per-memory type and not per-test. Add uffd_test_case_ops which each test case can customize for its own needs regardless of the memory type being used. Pre- and post-allocation operations are added, some of which will be used in the next patch to implement test-specific operations like madvise after memory is allocated but before it is accessed. Signed-off-by: Suren Baghdasaryan --- tools/testing/selftests/mm/uffd-common.c | 13 +++++++++++++ tools/testing/selftests/mm/uffd-common.h | 7 +++++++ tools/testing/selftests/mm/uffd-unit-tests.c | 2 ++ 3 files changed, 22 insertions(+) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index 583e5a4cc0fd..fb3bbc77fd00 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -17,6 +17,7 @@ bool map_shared; bool test_uffdio_wp = true; unsigned long long *count_verify; uffd_test_ops_t *uffd_test_ops; +uffd_test_case_ops_t *uffd_test_case_ops; static int uffd_mem_fd_create(off_t mem_size, bool hugetlb) { @@ -298,6 +299,12 @@ int uffd_test_ctx_init(uint64_t features, const char **errmsg) unsigned long nr, cpu; int ret; + if (uffd_test_case_ops && uffd_test_case_ops->pre_alloc) { + ret = uffd_test_case_ops->pre_alloc(errmsg); + if (ret) + return ret; + } + ret = uffd_test_ops->allocate_area((void **)&area_src, true); ret |= uffd_test_ops->allocate_area((void **)&area_dst, false); if (ret) { @@ -306,6 +313,12 @@ int uffd_test_ctx_init(uint64_t features, const char **errmsg) return ret; } + if (uffd_test_case_ops && uffd_test_case_ops->post_alloc) { + ret = uffd_test_case_ops->post_alloc(errmsg); + if (ret) + return ret; + } + ret = userfaultfd_open(&features); if (ret) { if (errmsg) diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h index 870776b5a323..774595ee629e 100644 --- a/tools/testing/selftests/mm/uffd-common.h +++ b/tools/testing/selftests/mm/uffd-common.h @@ -90,6 +90,12 @@ struct uffd_test_ops { }; typedef struct uffd_test_ops uffd_test_ops_t; +struct uffd_test_case_ops { + int (*pre_alloc)(const char **errmsg); + int (*post_alloc)(const char **errmsg); +}; +typedef struct uffd_test_case_ops uffd_test_case_ops_t; + extern unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size; extern char *area_src, *area_src_alias, *area_dst, *area_dst_alias, *area_remap; extern int uffd, uffd_flags, finished, *pipefd, test_type; @@ -102,6 +108,7 @@ extern uffd_test_ops_t anon_uffd_test_ops; extern uffd_test_ops_t shmem_uffd_test_ops; extern uffd_test_ops_t hugetlb_uffd_test_ops; extern uffd_test_ops_t *uffd_test_ops; +extern uffd_test_case_ops_t *uffd_test_case_ops; void uffd_stats_report(struct uffd_args *args, int n_cpus); int uffd_test_ctx_init(uint64_t features, const char **errmsg); diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c index e7d43c198041..debc423bdbf4 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -78,6 +78,7 @@ typedef struct { uffd_test_fn uffd_fn; unsigned int mem_targets; uint64_t uffd_feature_required; + uffd_test_case_ops_t *test_case_ops; } uffd_test_case_t; static void uffd_test_report(void) @@ -185,6 +186,7 @@ uffd_setup_environment(uffd_test_args_t *args, uffd_test_case_t *test, { map_shared = mem_type->shared; uffd_test_ops = mem_type->mem_ops; + uffd_test_case_ops = test->test_case_ops; if (mem_type->mem_flag & (MEM_HUGETLB_PRIVATE | MEM_HUGETLB)) page_size = default_huge_page_size();