From patchwork Wed Dec 6 10:36:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13481430 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 DB63BC10F13 for ; Wed, 6 Dec 2023 10:37:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8439F6B00A6; Wed, 6 Dec 2023 05:37:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F3E16B00A7; Wed, 6 Dec 2023 05:37:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F6176B00A8; Wed, 6 Dec 2023 05:37:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 4C12B6B00A6 for ; Wed, 6 Dec 2023 05:37:17 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1DB8D1A0165 for ; Wed, 6 Dec 2023 10:37:17 +0000 (UTC) X-FDA: 81536041314.14.58CD8DB Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf17.hostedemail.com (Postfix) with ESMTP id 5E41A40015 for ; Wed, 6 Dec 2023 10:37:15 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=PMIod3NW; spf=pass (imf17.hostedemail.com: domain of 32k5wZQYKCGsbdaNWKPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=32k5wZQYKCGsbdaNWKPXXPUN.LXVURWdg-VVTeJLT.XaP@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=1701859035; 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=LKRfVsFKiKRj/bBn07n7V+AeCZxk2uFtLWEya65cVnY=; b=H/TOcg8/qW9wU5lrJGKJvkSoAe6XEJo+yg4wOONqrXjsuS1ZxP9K92nh+3yOG8lyx7OCbu ZbIyfo2kATPbALM11Djqodj85tOdadk0bkA2qkxoDtXBWPPdUX2JdKZfx1uXR5SqMvAtli y69xz+OVlMuzdaaTmj6o3MyAwtkmXuc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701859035; a=rsa-sha256; cv=none; b=bdqqsJ8zgBGysFbCjB2NMGXzav79MlFbz/B2M6/Xj9iPUYtVI80m7vwyd7fXEdBII3D4pb npf5jLaCMYpZDFGVQFOLup0lPyOOhCB7y/GZfgF5lhL+Vsbf5ZDHy8PvKl5svCEhwvQT3t if9NKRbGKAAyQJ/jg32/TU8ZqfsCVcY= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=PMIod3NW; spf=pass (imf17.hostedemail.com: domain of 32k5wZQYKCGsbdaNWKPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=32k5wZQYKCGsbdaNWKPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-db547281f5dso5863038276.2 for ; Wed, 06 Dec 2023 02:37:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701859034; x=1702463834; 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=LKRfVsFKiKRj/bBn07n7V+AeCZxk2uFtLWEya65cVnY=; b=PMIod3NWPib74TVLoQZGE+olG4Ip240uKYDDs8GWYpz74xFFxpdvgR5yukhwRTtHfy TIiHVyO8bTXZ/7yHy2f6KqvOw9qxJvqNKvuCFO0FWRJDgt9deoF52fi3Hu3mvvuZx+1H +3WUGZ4m8uWeHNqwHyTIGBoI7dqPWw+KRvRWBjeSR4wLQYxEJ+xHqwOfqARSmgjlK5+8 GdAuh11odd63nKq8nBwp+y0ihSD9GmPF6XVzPMFur6vbvqHTjWWPJQIuPYf0NjQHql8t O4f4+lQVBa96TgRuaRVmpzSgZ4lXYNUB55KcTWTNHw8ovR/1cfCf6ZS+qFxjhlXTEgWJ Jcwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701859034; x=1702463834; 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=LKRfVsFKiKRj/bBn07n7V+AeCZxk2uFtLWEya65cVnY=; b=mMJhSNtgfbQQX8cjoTud1CATmA3ytJjeGB55/DF8l2MfXTnv97awZad3Kuayg0kHo8 oJwxaNZyauVVfFl8Aq6zK/I970DLHV+z7vic6rtEwJHhwVjNOFvp/nZDdT65McHtC99H EE5Nikl+JsgaEOhdDBWgOtDAZHtkHPR/RI6LU3eeX6Z8fnvOY9/svEzxO/uHkWhJGMC3 ffr5WvcpTbiPHdOVPMXxvX10F9QmgCoJji043yoE3JjnN/MYmI8eJGAZTXfIcDzSmYf1 2K/w4tNxCbXFG2qBWsycHuAk1P/FPc6t0A54NIfasmS1zG9hyYB0J19i8hubQshTP88N GSlw== X-Gm-Message-State: AOJu0YyBaRdbmME4Dg45NplPau4PBWREuu81tkQeb9xacdLLNlvPhW7D wTq3C2urdPutWvrqvKfrIA65k7hZtBY= X-Google-Smtp-Source: AGHT+IHftIhmpWTuhBJ4KgQdy7Iz+ajmipBw3xyDTOe9qFzmSjg8LtWMwYZC/utheufnhCJo9BaLVXYt0+s= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:73f6:b5e2:415:6ba5]) (user=surenb job=sendgmr) by 2002:a25:d095:0:b0:db5:4766:e365 with SMTP id h143-20020a25d095000000b00db54766e365mr5227ybg.8.1701859034586; Wed, 06 Dec 2023 02:37:14 -0800 (PST) Date: Wed, 6 Dec 2023 02:36:58 -0800 In-Reply-To: <20231206103702.3873743-1-surenb@google.com> Mime-Version: 1.0 References: <20231206103702.3873743-1-surenb@google.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog Message-ID: <20231206103702.3873743-5-surenb@google.com> Subject: [PATCH v6 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, ryan.roberts@arm.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-Stat-Signature: piet1hx463deee1ip3jg199eqrgcdzau X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 5E41A40015 X-Rspam-User: X-HE-Tag: 1701859035-671647 X-HE-Meta: U2FsdGVkX1+nUNmCqc9XqSsc1U/e62e/yexBlk0vBGYpRbzKlhmOHh/mPE8NlMVXTAHnRVPjTi1K917d2hBBak1s4tVfTdL8RRiVXS/7hs3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8+RVhWG6dNROKPtaloZGgGvF91XT3H7w82lXmI/+diUVCHwEF+KjGpS36/FRSWwq6QLkM2Rwfdi4wDv7+w3a0P3q3WiWraIs/c5uvPbew83+9tFAdEB/dxiqEYqIVXKMEPdhX1LvV7UtMgcrIQMgrnY/xHGqehZaCLgYbFt42Mq4T/5vAScecwoWJfEi7CkfHXE5mAk18KPQVKHBZCs6fd/1z0oJkyTT5vdTsFSX9mpe+YEfdjodrPtU465fUD1DDVrohPHRuueTgR30WAPz3nFpHYVGZB9dHKpU1X7gxfV8AxTwNun/sfq6uDIKjdKG4yj9XYcRF23wKKcIYG79NoX2z/6mjMEBvn0O7hKEXPj37IpWe9dMiTTNfhqRlRgszHYg8Z0YeBYJA5hainqp9k9GkCXeSMNnCnpYCGTRKDH3G2iFYQw4m1nkpzwz69kA9FZQqV2GVCefWdjVw== 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: 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();