From patchwork Fri Jul 7 21:55:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Rasmussen X-Patchwork-Id: 13305364 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 16549EB64D9 for ; Fri, 7 Jul 2023 21:56:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 83D298D0007; Fri, 7 Jul 2023 17:55:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D8F88D0005; Fri, 7 Jul 2023 17:55:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A0DB8D0007; Fri, 7 Jul 2023 17:55:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4420D8D0005 for ; Fri, 7 Jul 2023 17:55:59 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id F0FA1120149 for ; Fri, 7 Jul 2023 21:55:58 +0000 (UTC) X-FDA: 80986173996.21.37E1AFD Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf03.hostedemail.com (Postfix) with ESMTP id 304EB20009 for ; Fri, 7 Jul 2023 21:55:56 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=mSszojzK; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of 37ImoZA0KCM0tGx4AtB5DBBx6z77z4x.v75416DG-553Etv3.7Az@flex--axelrasmussen.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=37ImoZA0KCM0tGx4AtB5DBBx6z77z4x.v75416DG-553Etv3.7Az@flex--axelrasmussen.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688766957; 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=gK2BPE6zTmiKkfK2gtxYAq2cBVrZ0W+ejTntqdgctKA=; b=Uvh8VmefIUGlMMgYFULQaI3tAf5QE28b2UaU98JB4J34shlSHKvgtNZMO0CT7mYNQbApCd BDeoeZqo/mhDco0aj6DVcIMIUpiZf7WBG7CBXfPJ+05MgOvV/3yI7rr3ySTti3569/U1Ua oUw8sIpDcM3bWwRGL6lRkPF2HaTbnXc= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=mSszojzK; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of 37ImoZA0KCM0tGx4AtB5DBBx6z77z4x.v75416DG-553Etv3.7Az@flex--axelrasmussen.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=37ImoZA0KCM0tGx4AtB5DBBx6z77z4x.v75416DG-553Etv3.7Az@flex--axelrasmussen.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688766957; a=rsa-sha256; cv=none; b=63g6jR0vQsz16ztjzur6yNZW1EyOSgDGk5NvvWUV/hZdWypRMRf3CJNP4p7ghCV2mtRB0t ngz9LhOSBrPi6MjDPbAU1IAEC9nlFUoBGjqq9VI0r1D/QVgNkPi8aJYM1zYDNsYxyGMH5K WguxtRIj002ADOMwhYBhaDYPhLRUkew= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-c56c5e61ae4so2480386276.0 for ; Fri, 07 Jul 2023 14:55:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688766956; x=1691358956; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=gK2BPE6zTmiKkfK2gtxYAq2cBVrZ0W+ejTntqdgctKA=; b=mSszojzKEahxrcX9TmdDeq6BffcUFhBof3Wfa2NSLReCESkfHCMI7XDPflqSMkDGpn ouiK/1EZIjxsDpq0jMwqD9m1X62FyMq4nDzBgb6M7/ML2imJB1U5v1dc1l+ah8jMdnJe PB5xOLeeNwdXhcD53UzfTcq44+hoXfPErYaXguCDFgNeDDRdB2ZRmDfpfqDhBFUErms9 b4UKo5d1K8Kn+ry9fkThfTtz75Zrd1GT+xA0NJx4QctBIIrNfwI5B6zi4Oqa1PV6Le9z CZ6qPQtNTcVthIO6ODY++3/5NAu2trU9W9ps5V5xHMzx1D8Foq0j24NK0X2aUZ74o34R JWeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688766956; x=1691358956; 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=gK2BPE6zTmiKkfK2gtxYAq2cBVrZ0W+ejTntqdgctKA=; b=P12AKOTc8tpOii3cqJ6zFzWJneUhKWX6f1s6IsrH2oXcDaGMHJ4Tc/ZBPgJtGO5ydQ wDi6g5//zwFLQFxQvMZTIlev5vi7QfpBCS4PTwdIk6CH8QSDroqnf8ifPf800SQ1xivv tzC5j9TXjGURLwD7kSkPF3x08TgOEvNclaSzoYUyRhJDajEcqS04K9ur+S65/bg8F3aI qkiIuUnMbtKWVjRRAmoBgXDEVqqLbfa6b3U8L5g+FhvQX01v97CGamXSiRgN8UxEPope tOvZHNTf7V+6s9cO3wRmmr8y5vPBnul7lL9YONfgz1vGWKjPHDVod070PnEqp5qt+zsp M4kw== X-Gm-Message-State: ABy/qLbK5sF+u8j7dXvw6MtlKLBU1giksouzMLtoIdwFkUZzAjJus7IM lTEowYyU+38nb2+Mb43qU4lMfbCtYem/ykBtptZc X-Google-Smtp-Source: APBJJlFFlaqfrCAHxFCqM3Bx4zG+dvuvfGgO5ZnIbPvaXcko0/wlrp48kEZGBI/2IRBZ3QqzAWog232RIOlbEqwMvlQB X-Received: from axel.svl.corp.google.com ([2620:15c:2a3:200:c201:5125:39d1:ef3f]) (user=axelrasmussen job=sendgmr) by 2002:a25:f448:0:b0:bac:adb8:a605 with SMTP id p8-20020a25f448000000b00bacadb8a605mr43005ybe.2.1688766956303; Fri, 07 Jul 2023 14:55:56 -0700 (PDT) Date: Fri, 7 Jul 2023 14:55:39 -0700 In-Reply-To: <20230707215540.2324998-1-axelrasmussen@google.com> Mime-Version: 1.0 References: <20230707215540.2324998-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230707215540.2324998-8-axelrasmussen@google.com> Subject: [PATCH v4 7/8] selftests/mm: refactor uffd_poll_thread to allow custom fault handlers From: Axel Rasmussen To: Alexander Viro , Andrew Morton , Brian Geffon , Christian Brauner , David Hildenbrand , Gaosheng Cui , Huang Ying , Hugh Dickins , James Houghton , "Jan Alexander Steffens (heftig)" , Jiaqi Yan , Jonathan Corbet , Kefeng Wang , "Liam R. Howlett" , Miaohe Lin , Mike Kravetz , "Mike Rapoport (IBM)" , Muchun Song , Nadav Amit , Naoya Horiguchi , Peter Xu , Ryan Roberts , Shuah Khan , Suleiman Souhlal , Suren Baghdasaryan , "T.J. Alumbaugh" , Yu Zhao , 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-Server: rspam09 X-Rspamd-Queue-Id: 304EB20009 X-Stat-Signature: xcwyqaqkm9a1jaizxzewytmkz8p9nnhu X-Rspam-User: X-HE-Tag: 1688766956-989525 X-HE-Meta: U2FsdGVkX18Y2TPL9Js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GaJnC8XMFh+iLUaCY3SkGTzToHg8Mm48gOjWJP0BSeJMxuwxIduZmMSzEGgUP3kCwRbQJ/WvCVyb9xYAL5Nvr5PkIGV+79gPND3UjbHGVSMee9z97T8k656hGDC1bazg+WQNfxyCWJ37Bi62CGwHO9dSkH7lZvSe8vqpvR+tfeGrV+Bs526UqwDrHdLxLAuC6bbT7qbQblEGfoKSBN6Miahc1XQqT66U0zWKsskduTuiHbQmleKFlfepJjXIIHlX3piL/1gElRcI6lIR8f0yHi88zjmf/1Y1ry8PgEM+N2wzxfFGPP3U1HXtItV3fKPp9SE+yrbz26kc6n69Yr3xmDPYxhqucZGDqGNtKUTp2Vp/pH16oUpSWhw4EVg5htBAA2hZkq4fZrEezbltleW2CLwd9SAKCybf3I2JBLP6URtUSOdWEBw178cN2I7SekHIb6rZ3EM4SZu3UJUZKvKCnkAuZu5U4hFAx5ZQqihlLG90ZEhCL5WImWp2zj6lW6HVh+jG3YpOOFpnEej31ElXaehGr/TotMEa48Ox/VykJiENJL8bWMIFpDdzDayC+7ZQGuE2rpKicJ9Z3uocKlMOWJvsCCrgMwzjR0uDV70bdi7hASg== 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 Acked-by: Peter Xu --- tools/testing/selftests/mm/uffd-common.c | 5 ++++- tools/testing/selftests/mm/uffd-common.h | 3 +++ tools/testing/selftests/mm/uffd-stress.c | 8 ++++---- 3 files changed, 11 insertions(+), 5 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..73ebb97c7026 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, @@ -250,6 +248,8 @@ static int userfaultfd_stress(void) struct uffd_args args[nr_cpus]; uint64_t mem_size = nr_pages * page_size; + memset(args, 0, sizeof(struct uffd_args) * nr_cpus); + if (uffd_test_ctx_init(UFFD_FEATURE_WP_UNPOPULATED, NULL)) err("context init failed");