Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp29377380rwd; Wed, 5 Jul 2023 10:55:08 -0700 (PDT) X-Google-Smtp-Source: APBJJlGLn4GXZQdSuyBTaA0rSDObU6eankoGQZ6caQqnnq1d30Vh/aAfTzBSKarL7fHs0gB2dIyE X-Received: by 2002:a05:6a21:32aa:b0:12f:301e:10b7 with SMTP id yt42-20020a056a2132aa00b0012f301e10b7mr6576409pzb.60.1688579708216; Wed, 05 Jul 2023 10:55:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688579708; cv=none; d=google.com; s=arc-20160816; b=SRZx5WKWqHQEq2a3Zjhu61f/Z6GFSUPWmVA2orPabQmNO9uyh1kb58j/F9j5fCRTpO EPmhJavGK03pIkU3M81gNfdcYOetqiMOkz7/6TGEbLxHpYN4L1smYSnFHfkVEEXIzaod YS0nIibEb2igmiPqUGPic8G02KoLMUvEGXE/Spcancp+JB5NG8veVL8wIzxSq2z8dk3j m+LqyzotwDMXQ9Gu+72fzAHRvT4BOHoOQutXdN/Oy0O+6vdiq1lv3kl2xkAAmXZSteLy nz0tMSbCD7kM4mwRVYRIQDLMMf7NPEQXuqcZE8y2lWHcDpn1fMVRbvw+uAG7kDUN3UF0 28FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=aEI4v+2KKn+EkDZzdrBmikEj6qMvmv1XLjDpHecmTZc=; fh=/F3QcTr8eJcSmABKKKB3V4QImlxNjHJ11N2kFsUkZvk=; b=nO22ynVE0V/cGPer6bEqrkux+p+g4eeY4P8EpnC/MhKCks0j9NkD/Eteh6aVmP4ZNW LKubWBsL+TeZTyQO5f+1ap45G08NjtTguL1SNlW8LFeLxTgn3Ux5+wRO5VRgJWS/j+Ld x4/Gitu4QLRNkjYecsFfjBcnETUmyIeSjFnIV2BgMWumzIkjgXmtq6r+f9h39WwhWEiY uQ3TBV6kXmd9DxnOk889fYPSUsDHWe2RrANk+UANm5eQkF/47ahC/AN/wGCevwQkEYx0 JkN6qhw3hHxBRtHrO0yvgHBeN/mXywZqZ0QGJrycgwm1Bvc0PtVgJOQTX4dhMpVPLc4S nKOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="f5HN0rW/"; 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 c14-20020a631c4e000000b00543ae703b97si23564511pgm.209.2023.07.05.10.54.55; Wed, 05 Jul 2023 10:55:08 -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="f5HN0rW/"; 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 S230009AbjGERvO (ORCPT + 99 others); Wed, 5 Jul 2023 13:51:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229645AbjGERvN (ORCPT ); Wed, 5 Jul 2023 13:51:13 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D959EE3 for ; Wed, 5 Jul 2023 10:51:11 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-99342a599e9so518856666b.3 for ; Wed, 05 Jul 2023 10:51:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688579470; x=1691171470; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=aEI4v+2KKn+EkDZzdrBmikEj6qMvmv1XLjDpHecmTZc=; b=f5HN0rW/zmfb6pFzjhlVkLATVIc8CO9MM9qNTqXTMEchOXn4fIxtcz3Bx9eyCqCr2Z M5Z0iUelv4vCsc15ld58d/0zM9UUJWAwN+XIleuO4uVXGFuUytLSMFn2mcLd7qm+OYZ1 txF0HDVGO4e0+Hr8h5AqLUey2XXij6T+Mts2sUaS2d97sVSzm9XURFST97gRUCjUd6ZN +Knu2ZIlBqLLoX3vOXvgJPO7sE0U6CsNwW92Su3zO87HD6GAacOyAX02RaADnRwZ3+j2 m4p1oaf9lM/wlHWC1mrl0h9YdVrFcv8uLiTLvIrPNPSZf2hUt7l/wo4cEKxx+wobVv0G MoXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688579470; x=1691171470; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aEI4v+2KKn+EkDZzdrBmikEj6qMvmv1XLjDpHecmTZc=; b=CDiVifV68rdTdbP8tmVlq1govyIsvW8SODybnZ7qvX/AsusgDskToCc2dohbHsHAI9 yfx7IAMX+Wl+oS7OtU/Zv0vtMhFh7kmAGdpqzQ4auWOa0IJe2URU0Yq5FWdYZSs1fdfo osDYZ5VNfpDTP/BZDyvg+87kLmEYXs/9R+rIDQQkUBT5N7NbjNaCpRWiFD8VMplQifyj NeShTXpfXhonNU8bp5Q856iJl9ihk6TvhZEGNi7Jt2o1yCMyjmVFXOVvNYRumhVrAtas PsUaBdP3COIV2r7rgK70zThVukXhWJRU7NNhlGnKXa++7w0Z609+xxaSkJTjR93M/oAR X84w== X-Gm-Message-State: AC+VfDyqrPclskNGgdoyPXc/1vEPqzeQZXokNT/vWSTGb6qeIgbN8oWD T86nyvAtWztqyvY3q3plqeFF4PdUnkXOm6e5/wtsKQ== X-Received: by 2002:a17:906:f1d3:b0:978:6a95:512d with SMTP id gx19-20020a170906f1d300b009786a95512dmr11603991ejb.11.1688579470177; Wed, 05 Jul 2023 10:51:10 -0700 (PDT) MIME-Version: 1.0 References: <20230629205040.665834-1-axelrasmussen@google.com> <20230629205040.665834-4-axelrasmussen@google.com> In-Reply-To: From: Axel Rasmussen Date: Wed, 5 Jul 2023 10:50:34 -0700 Message-ID: Subject: Re: [PATCH v2 4/6] selftests/mm: refactor uffd_poll_thread to allow custom fault handlers To: Peter Xu Cc: 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 , Shuah Khan , ZhangPeng , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_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 On Tue, Jul 4, 2023 at 2:03=E2=80=AFPM Peter Xu wrote: > > On Thu, Jun 29, 2023 at 01:50:38PM -0700, Axel Rasmussen wrote: > > 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/s= elftests/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 =3D uffd_handle_page_fault; > > + > > pollfd[0].fd =3D uffd; > > pollfd[0].events =3D POLLIN; > > pollfd[1].fd =3D 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/s= elftests/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/s= elftests/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, uff= d_poll_thread, &args[cpu])) > > + err("uffd_poll_thread create"); > > irrelevant change? Right, I'll revert this. In an earlier version I had a more substantial change here, and just didn't fully revert it. > > > } 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 =3D nr_pages * page_size; > > > > + args =3D calloc(nr_cpus, sizeof(struct uffd_args)); > > + if (!args) > > + err("allocating args array failed"); > > + > > It's leaked? > > Isn't "args[] =3D { 0 }" already working? That works, but GCC can warn in this case (-Wmissing-braces) depending on the definition of struct uffd_args. I liked switching to calloc because it avoids any possibility of that even as we add/remove things to struct uffd_args in the future. Since it's a selftest and this function is only called exactly once, it didn't seem worth the code making certain we free it, instead just leaving it to be cleaned up when the process exits. > > Thanks, > > > if (uffd_test_ctx_init(UFFD_FEATURE_WP_UNPOPULATED, NULL)) > > err("context init failed"); > > > > -- > > 2.41.0.255.g8b1d071c50-goog > > > > -- > Peter Xu >