Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp32498375rwd; Fri, 7 Jul 2023 15:16:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlHVntBHWNi21pCkcaHM3PU0nqoEpu5Cj0s1iYhht4rGiZ2dzViYIQF6pFdyVHqar8hHZYBu X-Received: by 2002:a17:906:1dd:b0:993:e512:cb59 with SMTP id 29-20020a17090601dd00b00993e512cb59mr570975ejj.9.1688768201162; Fri, 07 Jul 2023 15:16:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688768201; cv=none; d=google.com; s=arc-20160816; b=agFkRcCoV24TpTeRHLvHWgP7nbxNz8ga7Ck5Z3yrk8TbX55lAii38eiseoPn/XSqhM Jil6rdqJ40V/I+eXNdAMb3/205bA2v4XyK1QU86YPYZhDxrCjfeDhc9YwefESDXMq+/j wUDDcLxtUosqdhzSm1Krh9sevZy9ECBa5+QgMwKlrgh/anbrdGWP5W+fhE1x33Mp8SzD XVJa3qPoiBeDZ7FBj870YbtFx8wyqgHZWUmHgB5kVJVppA125qaNK37zxdN/0GQAqxX1 HAMfbnHLk+gVd/vdlaQSU9+fM/B6K0DoFhIKe02MaF1+YZ6Kab4sJU1oWGqGBYUfFqiD uKrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=gK2BPE6zTmiKkfK2gtxYAq2cBVrZ0W+ejTntqdgctKA=; fh=Opjbx899L+35XA6SNQJRoMm3wFpvelEj3IooMxkZLjI=; b=riaUvF+u1yM15Ep+frZYnJfbKLqbzGReP+ebl7BfY1pwWqFnM8Sm27J5YSBvoeNRkj oSREJHJx53pjcXWCX3v1QvRQ9HzM7fAOeYuH1pss9XVLyV+PSbYQ7eXp93G63PO36QWX J1ByrQz/9PX/7M2rFhRIojebssc6Hlt1HwYxzjYDb70vCfK36/HPgsWs/FfToP8+vtNa ghy/q8uWRPHWLCynvzPrEn0zACiABUeigd7xpFIdG+H7Epv1zlYCLuNlTnTELB0wB9Ky RR0hD3/bf9ZtbLU87BvezD3jeYmLA245gR5q3LRkr4YSbeOJCYU4t67EDD8+hBptHxpp gkTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=mSszojzK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g16-20020a17090613d000b009655fcff588si2671381ejc.835.2023.07.07.15.16.17; Fri, 07 Jul 2023 15:16:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=mSszojzK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232796AbjGGV4b (ORCPT + 99 others); Fri, 7 Jul 2023 17:56:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232526AbjGGV4E (ORCPT ); Fri, 7 Jul 2023 17:56:04 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 187F826A2 for ; Fri, 7 Jul 2023 14:55:57 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-c4f27858e4eso2472571276.1 for ; Fri, 07 Jul 2023 14:55:57 -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=GlsYMQDE03q0VGbt1be6ieZYq2xDX7kIjLGEkde1jPW0ypbqMQIHTohs/nAFuFPQbt GXzzOmRcIv/4zDqhgmJ6SDtmTL0dX3L+TW9s5e8+23exc//qH2TEaUk7EZY9acN4rWqq LnEOE/x69hjVPxultEKSjqJ1BgnnRLwZkhDyymPGBBw/wiqNUUBu1YIz4+VysvfQmqDa F8WDpjSWSZdpE4npCSWtUAsdSkPFZPiuCl5UBPxwbgxQAfiatsQiY1DcQkuYlj2nVI0J GsqJWquNDUVTAR7lk8dpFwXRIRShPt+YCj+/3YeGPzE6r1xv96J4PL9kyootLDT5jGYP evPw== X-Gm-Message-State: ABy/qLYpME0zNG6lHAZmVahvs7K8IK6t1+lN9TxDnFMorJTwvbeGJcnV 6uG5NA6p+53uGgpnDshJHI6L3uKFa2koBjBLu76G 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 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"); -- 2.41.0.255.g8b1d071c50-goog