From patchwork Thu Jun 29 20:50:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Rasmussen X-Patchwork-Id: 13297314 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 9BDECC001E0 for ; Thu, 29 Jun 2023 20:50:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C8C18D0006; Thu, 29 Jun 2023 16:50:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F1E1C8D0001; Thu, 29 Jun 2023 16:50:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C87948D0006; Thu, 29 Jun 2023 16:50:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B82BF8D0001 for ; Thu, 29 Jun 2023 16:50:56 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 910271A0CEA for ; Thu, 29 Jun 2023 20:50:56 +0000 (UTC) X-FDA: 80956979712.02.552EB32 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf24.hostedemail.com (Postfix) with ESMTP id AD2B1180007 for ; Thu, 29 Jun 2023 20:50:54 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=3cQsv9mP; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3re6dZA0KCC4KhOVbKcWeccOXQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--axelrasmussen.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3re6dZA0KCC4KhOVbKcWeccOXQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--axelrasmussen.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688071854; 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=0eR1m0YpsGhZ6GlqZ9XuYhhV42VymJr50nJOc8nZiNo=; b=IlpEpOp35astXfaGf5gGt02iidIACX9u5ucZv1vgjUU44KDKTeIO9cUKDTQx7maJtRCdgT ScRSWuaIA4jvmV2VAl7fCjvnB0Hgbfa9bDkTQxhIQtxFs1/oBksYX7wa91VI3K6Wp1z+1Y kT0fexUzk1mCMggezT6Wyk4te6nzGTk= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=3cQsv9mP; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3re6dZA0KCC4KhOVbKcWeccOXQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--axelrasmussen.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3re6dZA0KCC4KhOVbKcWeccOXQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--axelrasmussen.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688071854; a=rsa-sha256; cv=none; b=i1/oK1oYjIbf41p9Jub8NCc59stsbeKELxTHpSCZzhGNLDjkC+paVn7Z/aS/8TTOEH6U/l b/wp4RRsKM6sq5Zz+IwM6f0iz+iwWzdsCoqXST+lRkW8OdP039Q8IK9JTOskmoIxnCHlCP DHFhvTtgFx6MgjhUJ8MRjTjI5CIt+5Q= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-56ff7b4feefso9446787b3.0 for ; Thu, 29 Jun 2023 13:50:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688071853; x=1690663853; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=0eR1m0YpsGhZ6GlqZ9XuYhhV42VymJr50nJOc8nZiNo=; b=3cQsv9mPUr/J47bNoSUJhw0yv5GwYe9VZP9mYSYio932WB5S45QeiLp3sUUgqKWWVH dSxCe5jkZQeEy91/Za56iq/BaKt7D2eO5CKC5tFRQYXavX5XUCleRaiiLN/LYOpTc3Q5 TlyJDS6v9N9nUKx4AeHRICAHwHnZXdJB2EprVzPDgrV+x6B+GNNBpU5V0gfMamqVpbki nvs6vizS27HjxtsanHmKiVM1v+306yk8JhmYhHT5HisNsno4bY2z/AyQxRY5mcHLj0/S 73GQMk4SEbiPfcHxLnui5ipf505zkiJKpuRvNi5XJnjd8ujS1kh0z5BvTGrPJHuMpVHk xgHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688071853; x=1690663853; 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=0eR1m0YpsGhZ6GlqZ9XuYhhV42VymJr50nJOc8nZiNo=; b=eXaD+5q9vdnv4fedrilU4YJta/sGpbAJAAx9ktHjCpPg/Jt3xujiqQH9k3IzDZR+Te DbWRB/AwWgppwBq/SmKdeNyZyc6BuLr0Dhj0u0mM3+iZo32gEWSLtEf04RB1BLpybGd0 8/zP3Q0hAVh8cT5bt1piYAogRhHgeNtkT+u4xQtDsnN9DNgpCWsBkHHw72vAj3nfF9ZF 7w3uvGvVrN3A3BRG6yoBC++mEha/6GHkxQ2oOVLVflM3FkdwzwZEgddM5rHMsUC/h+NE crDKEA8iAW3drp1I880fdi8yofs64L5b3zR7WYsMutkiBppgf4Wb2mvs7YquJcZ5k43a 04+A== X-Gm-Message-State: ABy/qLZ5qISNMMnrCyGXPlTSi2HDE1ql79OBhu4qPZxAmH9Tw+y5zNJ2 SjGFn9ZgkSXDeyp0hqDZ/hJNLjuCz2Ni1/rkX7Wn X-Google-Smtp-Source: APBJJlGMR6Hew5dlxFm7tULAhbAWqjtH0IRMMwzkK9vijNpv3CfU43JDb01xtUzDErorDPisxqOLpILC+1eZPblYAKLk X-Received: from axel.svl.corp.google.com ([2620:15c:2a3:200:e20f:5917:3efa:d4bb]) (user=axelrasmussen job=sendgmr) by 2002:a0d:dfd0:0:b0:56c:e2da:f440 with SMTP id i199-20020a0ddfd0000000b0056ce2daf440mr4758ywe.0.1688071853655; Thu, 29 Jun 2023 13:50:53 -0700 (PDT) Date: Thu, 29 Jun 2023 13:50:38 -0700 In-Reply-To: <20230629205040.665834-1-axelrasmussen@google.com> Mime-Version: 1.0 References: <20230629205040.665834-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230629205040.665834-4-axelrasmussen@google.com> Subject: [PATCH v2 4/6] selftests/mm: refactor uffd_poll_thread to allow custom fault handlers From: Axel Rasmussen To: Alexander Viro , Andrew Morton , Christian Brauner , David Hildenbrand , Huang Ying , Hugh Dickins , James Houghton , Jiaqi Yan , Jonathan Corbet , "Liam R. Howlett" , Miaohe Lin , Mike Kravetz , "Mike Rapoport (IBM)" , Muchun Song , Nadav Amit , Naoya Horiguchi , Peter Xu , Shuah Khan , ZhangPeng Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Axel Rasmussen X-Rspamd-Queue-Id: AD2B1180007 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: rm1yw1dn1sgi63it6un5s66u3rwsxbi5 X-HE-Tag: 1688071854-329984 X-HE-Meta: U2FsdGVkX19txrONgssApzbsWxQog10plWfxccPgH4mTWpjH0ehDtf0jYzPiAeKwjvMoeRkxkgsy95gGBBO96YkUWbEk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e0T42fZMNtQKJmdBJzpv+hWxcMJfGFp12et0IQRWr4VhP8MSuWc9DYMdv+6aNVj+Lco8BF9WexKxsymz39VToDCqNENtyLkbe7nP79BFXN2QZ5jBKO9+9dtHIqgfOgKNcx8AnzDOYDrtA4WtoCz3Y3c8hlKWVvER4v61Rip6baqdrIeb9rVe8zL0EBYnPMTKcfCiNQxt+q9E/gD40707HVXy4UrG4/WL5tvpbXJpI51U41h1gEbkeUAicUO4sjr3rtN+3neRoMJyrt/5MgxVbNi1QeugW2mcyvHcgLa1NKm3muKa28p0AP6a7BwraH2VhMIvcRmkPxqGTItlbwoPNQQmXEbLHy2C9bCJIRsPcj2mBCQc7km03DfNyQc9DIugw+9KN2UBZ+vc6Tgg0WPCK74fNeCbMLBsP4+VC3XU0Ia9H9zI61rk692VhtxwIGdRvRtCC1O6zmjKjosl/IQrpaiXkXiKqDxjP2oG/u+JhmWnHHF7VVK5rRkyMT6psfzPJ5rWchtupElAaGvTnx0ZkQmG5QPaUdFEA== 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: Previously, we had "one fault handler to rule them all", which used several branches to deal with all of the scenarios required by all of the various tests. In upcoming patches, I plan to add a new test, which has its own slightly different fault handling logic. Instead of continuing to add cruft to the existing fault handler, let's allow tests to define custom ones, separate from other tests. Signed-off-by: Axel Rasmussen --- tools/testing/selftests/mm/uffd-common.c | 5 ++++- tools/testing/selftests/mm/uffd-common.h | 3 +++ tools/testing/selftests/mm/uffd-stress.c | 12 +++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index ba20d7504022..02b89860e193 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -499,6 +499,9 @@ void *uffd_poll_thread(void *arg) int ret; char tmp_chr; + if (!args->handle_fault) + args->handle_fault = uffd_handle_page_fault; + pollfd[0].fd = uffd; pollfd[0].events = POLLIN; pollfd[1].fd = pipefd[cpu*2]; @@ -527,7 +530,7 @@ void *uffd_poll_thread(void *arg) err("unexpected msg event %u\n", msg.event); break; case UFFD_EVENT_PAGEFAULT: - uffd_handle_page_fault(&msg, args); + args->handle_fault(&msg, args); break; case UFFD_EVENT_FORK: close(uffd); diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selftests/mm/uffd-common.h index 197f5262fe0d..7c4fa964c3b0 100644 --- a/tools/testing/selftests/mm/uffd-common.h +++ b/tools/testing/selftests/mm/uffd-common.h @@ -77,6 +77,9 @@ struct uffd_args { unsigned long missing_faults; unsigned long wp_faults; unsigned long minor_faults; + + /* A custom fault handler; defaults to uffd_handle_page_fault. */ + void (*handle_fault)(struct uffd_msg *msg, struct uffd_args *args); }; struct uffd_test_ops { diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selftests/mm/uffd-stress.c index 995ff13e74c7..50b1224d72c7 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -189,10 +189,8 @@ static int stress(struct uffd_args *args) locking_thread, (void *)cpu)) return 1; if (bounces & BOUNCE_POLL) { - if (pthread_create(&uffd_threads[cpu], &attr, - uffd_poll_thread, - (void *)&args[cpu])) - return 1; + if (pthread_create(&uffd_threads[cpu], &attr, uffd_poll_thread, &args[cpu])) + err("uffd_poll_thread create"); } else { if (pthread_create(&uffd_threads[cpu], &attr, uffd_read_thread, @@ -247,9 +245,13 @@ static int userfaultfd_stress(void) { void *area; unsigned long nr; - struct uffd_args args[nr_cpus]; + struct uffd_args *args; uint64_t mem_size = nr_pages * page_size; + args = calloc(nr_cpus, sizeof(struct uffd_args)); + if (!args) + err("allocating args array failed"); + if (uffd_test_ctx_init(UFFD_FEATURE_WP_UNPOPULATED, NULL)) err("context init failed");