Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp28161166rwd; Tue, 4 Jul 2023 14:13:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlHC5kLxu+apJcyWtnhNgG/1yIhFzhnafwk2tv98idz5NY8aRJ4BEY8nFslzhnfLtP4Eo8cx X-Received: by 2002:a05:6a20:938f:b0:12f:9e14:7a9a with SMTP id x15-20020a056a20938f00b0012f9e147a9amr228652pzh.54.1688505181049; Tue, 04 Jul 2023 14:13:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688505181; cv=none; d=google.com; s=arc-20160816; b=zlCSFBM5xryodnlHYdzoAYq0cDpzPgxWb9aN+CQzlvFN9Gvo+nCnhTrasOMScVIjHF YMIpaDuT1q+oYBnJdkDWI9jbcCYd6Dnj6PHxanWuMC678dGEI97ns59Ky1cE460AQEER VYWASYssabqKyxKUpB9HlenV2Ie+GtOm55GVERGNsF2Q0OCOkleOn2mKSBj7+2PeXL7+ d8936TMZXD7GWzI2WbH1yCydQgWCLMl3Xt91irvdNjSa+XpXycwUVjREto6wTuN1Jq63 Obl37mhYioJRGB1vh25EKxHMy1CArofABjZUShYNPM3BNQIRu7W337AoGYZxNzULfZBO ZYYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=bTm5iRt8zflfiJ3ZPlJNpWMOOG3kiO0nsowNZ4n8eHM=; fh=0t4louP/8+xP3ORiRbUZtig8/xKb5OX3R1/WptJFEDo=; b=hyPJcXZexWukr9WvCGzsvB6uRYrl1T7s9kWO961tY8mUvPGsc7lYol+g59knyQXzC4 Jrt+gunFes7sFJXC3x/4yuFT5Ard6rd2lulaOB+sWif34jRzIksnFIF3ArMSTh1cEnRx LUlGjCJKR7qXAkp8faewM0CiHnkKtrcRIptMj3dtrQ32q4TLNw/n91VcYlUWKIGpF8VT mSWzdIUuyY4rQX7yv4dgPCzmBrp5HInJDNLK3r7SoJwZo8V7dC5YXWaS84TOqTDFbBmz o8S0ojMh0u1UAviwvQa168Or3dLuvBKhv7A8rA8YwiCoUtf1Oy3SJhMs+0W7VxmpFZQq 7WAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DCquZtGd; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g3-20020a63e603000000b005503f26673dsi20973053pgh.230.2023.07.04.14.12.22; Tue, 04 Jul 2023 14:13:01 -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=@redhat.com header.s=mimecast20190719 header.b=DCquZtGd; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231140AbjGDVEr (ORCPT + 99 others); Tue, 4 Jul 2023 17:04:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229895AbjGDVEp (ORCPT ); Tue, 4 Jul 2023 17:04:45 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DD021704 for ; Tue, 4 Jul 2023 14:03:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688504632; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=bTm5iRt8zflfiJ3ZPlJNpWMOOG3kiO0nsowNZ4n8eHM=; b=DCquZtGd2/sBTpoCQIoiRFVQhgEoxublmgwL2tIXsd+AKsXG3czjiHm6Z7Q1QCaX1qO6+P qIsXZDO95VtV2aUesgIb9BG7T4i4LPXmMUEvTzPI0oyRCGQUN6ULhIpqTYpA24txDwOayT n4i7UH2kXzE06OkT+lbDCQCYjFBnywU= Received: from mail-yb1-f199.google.com (mail-yb1-f199.google.com [209.85.219.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-626-ejo3PornPLeMk8j3GO4mrA-1; Tue, 04 Jul 2023 17:03:51 -0400 X-MC-Unique: ejo3PornPLeMk8j3GO4mrA-1 Received: by mail-yb1-f199.google.com with SMTP id 3f1490d57ef6-bef331f4938so858968276.1 for ; Tue, 04 Jul 2023 14:03:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688504631; x=1691096631; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=bTm5iRt8zflfiJ3ZPlJNpWMOOG3kiO0nsowNZ4n8eHM=; b=dk9NLgfeusafI/QZwN8htkdyDyKUDcj7Cak7KNaDW8YDi0BTpg+rMC4Wmh2NssY5X/ 68uSMDJaVNWt2sXtbY5MTBfyTzp7V4g4nkpAHqt8Zq7mHz/el3c3E0yzvsRuu9900DEX 7mi4+6rmR6VDaDoRaZ6EvJrAzK1fZ3iFwXkcZytGG1Kx6X34jag2hZ0NmfdQHKcTDzAM 07fVIo1UqCTeZHxLTWvASzOmPOBakV3b5FMysXBOsve/PTXIJ8ZZpHpM2e7EsMTkBUo8 s9TUUVtBh9WKH0RpQSzhHKXmHknKqGeDGdCbnfwjMWHlXKDrZCOSqXT4jy5wKTYCcMym NaVg== X-Gm-Message-State: ABy/qLY+8G0YCql3Tsb2GwHtb71HCqiv04DNvHOQixl24tlHyenV5pHi Pgu33Nv8BW/aWZPGCN7jB1YBJ/f8VWqP5qvqaYHXE+HjdWHhF8Xv6TMAeSepAwSHgENFBE/gZVc QLHn15XoO2joCcj3x1LUVEKDS X-Received: by 2002:a81:5256:0:b0:577:296:af5d with SMTP id g83-20020a815256000000b005770296af5dmr7772621ywb.0.1688504630735; Tue, 04 Jul 2023 14:03:50 -0700 (PDT) X-Received: by 2002:a81:5256:0:b0:577:296:af5d with SMTP id g83-20020a815256000000b005770296af5dmr7772596ywb.0.1688504630457; Tue, 04 Jul 2023 14:03:50 -0700 (PDT) Received: from x1n (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id pv16-20020ad45490000000b0063019b482f8sm12934335qvb.85.2023.07.04.14.03.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jul 2023 14:03:50 -0700 (PDT) Date: Tue, 4 Jul 2023 17:03:48 -0400 From: Peter Xu To: Axel Rasmussen 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 Subject: Re: [PATCH v2 4/6] selftests/mm: refactor uffd_poll_thread to allow custom fault handlers Message-ID: References: <20230629205040.665834-1-axelrasmussen@google.com> <20230629205040.665834-4-axelrasmussen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230629205040.665834-4-axelrasmussen@google.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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 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/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"); irrelevant change? > } 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"); > + It's leaked? Isn't "args[] = { 0 }" already working? Thanks, > if (uffd_test_ctx_init(UFFD_FEATURE_WP_UNPOPULATED, NULL)) > err("context init failed"); > > -- > 2.41.0.255.g8b1d071c50-goog > -- Peter Xu