Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp21302644rwd; Thu, 29 Jun 2023 14:06:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6iJYeiM+cF0rxDVD1+yN5ofWNDRDCYCxepzCaakbOJFMertuU/44K+KeV+9KCJJT6at3Sa X-Received: by 2002:a05:6a20:a8a5:b0:129:9ba0:1f3a with SMTP id ca37-20020a056a20a8a500b001299ba01f3amr702716pzb.14.1688072766310; Thu, 29 Jun 2023 14:06:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688072766; cv=none; d=google.com; s=arc-20160816; b=fWznJscD9rF/DiD4uuGvtqboueVfkWbedargnONBW36tsEkOX9qRc89EfsgZlE7cVl hMMJexaSWJt628wDMIdBhvdFezLNIn1v+ZdQ4UqtXE0cIqaUWm3Qh5K/B+fXQhTCwQdT tf2MfkpGmymauxjn7NWajFjDgcKF0tdJxEhy81RVnLVczYxYQNfZEMW2U1w+PCM1Si4J y+lOvzIqucULNXgoIznQNV3LXrGsVfjxQLrY5NwGNCYZj9bo38YAWbJTgI7EbYHifpvc U7U//NSn4OmzzSWNb0IWVuwT8kCFBs07bW2jJQLT0RDCyXx9+phD0TPmT+ZxCFUJlM4L JDEA== 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=0eR1m0YpsGhZ6GlqZ9XuYhhV42VymJr50nJOc8nZiNo=; fh=eRaYFbc68TLHCmej1r/Q9kziindMZl6i1kh9xMHvl2k=; b=A1RKAF0O3GdE1VfqUXXqaNlaBbIiFl3CQpBQhJX3QOLeta155Tl0yj+IEeUJdTphtH gidHowvf7G50u2AwHIQgtadpfnB4dmmATE0qexdEs+RdOQi/y21ciBRXWE1pmwUfLspV mng25heQc659nq5ltNUarvu2YFEJ+lygfLeJvAU+RMy7ZOn3Lze5qMWp0A9mr0CYLr8+ dtF6aY2xVAZNQ5/WbZ4bBCIuxDRtnUjV8iGn2icOgcv8YEu7zgBID1bh6D721kUFGkPz RYQ1d01vN0ybVhlLpmwgE5gk+Q7H9qPjWlGrrLVjh6toILD9K+S/mZ+jMKkgPrnBojpX /PwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=3cQsv9mP; 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 s7-20020a170902a50700b001b54bdd6412si10463959plq.396.2023.06.29.14.05.36; Thu, 29 Jun 2023 14:06:06 -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=3cQsv9mP; 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 S230040AbjF2UvH (ORCPT + 99 others); Thu, 29 Jun 2023 16:51:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232238AbjF2Uu4 (ORCPT ); Thu, 29 Jun 2023 16:50:56 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F66935A5 for ; Thu, 29 Jun 2023 13:50:54 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-569e7aec37bso9293437b3.2 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=IUwsO4EYXcaRfIoj5C/zhY8dV0n1vDhtbpcCj3HmFnXy5r5nYhthc65rNDZY1h52gs JUOLNsFcDxGzPU524VABQpzG6VpU58GgpFK8GRgrYa16oE1Mxo0043m4VnUGQcnCmF2Q 8T+XhwJWZV472eta4wHi969Lw/71gzajE3LgcGKZPAzvnv3e1hBQu9WULs1uIPfwXdmF Rj6SXaXqffo+J7bTeORM03hpVrOZ06bbljQUzn6ycfBUEchoL4yJkqYNphe+V7t4n2XC DIrr/AM14B1/GmG4Bjb8bAbDesNeVbcU5LGvQGlO/+EbdznWJ/aimbbc/haaotWqkem/ eCMw== X-Gm-Message-State: ABy/qLb2CUFE9WMIWxtEZu/S3FV+ZSu4LMBGTyh4ndhS2uPRDt3Cb4gZ 9FdCyULUQjPPGfQpupUp8g+6Z/25wml5L+Q6PX2s 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 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=unavailable 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 | 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"); -- 2.41.0.255.g8b1d071c50-goog