From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E509AC43460 for ; Tue, 13 Apr 2021 20:15:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7E94D613D1 for ; Tue, 13 Apr 2021 20:15:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7E94D613D1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 129C46B0036; Tue, 13 Apr 2021 16:15:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1011B6B0071; Tue, 13 Apr 2021 16:15:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE37D6B0072; Tue, 13 Apr 2021 16:15:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0105.hostedemail.com [216.40.44.105]) by kanga.kvack.org (Postfix) with ESMTP id D050B6B0036 for ; Tue, 13 Apr 2021 16:15:43 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 858BE181AEF2A for ; Tue, 13 Apr 2021 20:15:43 +0000 (UTC) X-FDA: 78028449366.12.336F732 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 3DE84E4 for ; Tue, 13 Apr 2021 20:15:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618344942; 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=z6jLMxHXDVRiXYyQcd5eAsrnA6ok/2H8Sdo63BFQ8u4=; b=Yzh3MhxzIK7sxOFXUbX5mlF3h6M8Q7haam0d50DM5YGOrJPGWtscD+3/VwGKiH4ZIl0zJs VDoFbZULK86eTgqpVx1NMbHSCh6eZjNTdPuo98dmZMCiGWjtQhKnQXxOMGYSXKQGZ7NaYo 384/LqvbixdLwqksGVPaebeQZ5Um0oo= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-437-5_EyoVBAOqyYy7Yu6hFieg-1; Tue, 13 Apr 2021 16:15:38 -0400 X-MC-Unique: 5_EyoVBAOqyYy7Yu6hFieg-1 Received: by mail-qt1-f199.google.com with SMTP id j10-20020a05622a038ab029019f472c0820so445567qtx.10 for ; Tue, 13 Apr 2021 13:15:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=z6jLMxHXDVRiXYyQcd5eAsrnA6ok/2H8Sdo63BFQ8u4=; b=g8CZL2PR+6mtUKI/DNShB9jq4S1g22CbK+dfunGC7d3FD63F6cAx7oZHZxj7wPRqJ5 mgWzYeCqMU6Xz7Bu8ebniF80EFjHvt+zApWMm14FefdULeTolyz9hhmNUgX3/UCcUsJ3 +S4EckTBt+6b6gedSG+wvruX2t5VV6ofHST6QkzUdzbd64y2KmRdIVGmBb70MZ96N9aK H3D7x2ONuYI8deBXvugjC/aT2j7RvO67oArj6VOs9e76skYFznpqH37hCYXfT9+mWTTk ewECFiDIFYPb+Q1aiLrQKeRLaOcdjUcCNlRCOl9mAxrgo+QiE0Gf1fgp9sK3QgGBBnRa UzWA== X-Gm-Message-State: AOAM533hUDcJrN/Bdqiy6clz9DP8ixwKrmpS9j95499rL2d6P2Qzr89+ ELOSd/6kBN1Cd+3c+0g/0SQrj2Xl3I8U7j3BWIB5Fn4snXhnCwczXIysegGVtteWysmk/OVyStt tCfQrOsFiHlg= X-Received: by 2002:ae9:f503:: with SMTP id o3mr32222749qkg.331.1618344938277; Tue, 13 Apr 2021 13:15:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzk0HNq0oDNyEr5ELMzeUTmw4uMriVRz0Eo5dEdf+xlarAnuXBL2LazN2KzuwaIREXFINZXmw== X-Received: by 2002:ae9:f503:: with SMTP id o3mr32222721qkg.331.1618344937981; Tue, 13 Apr 2021 13:15:37 -0700 (PDT) Received: from xz-x1 (bras-base-toroon474qw-grc-88-174-93-75-154.dsl.bell.ca. [174.93.75.154]) by smtp.gmail.com with ESMTPSA id l16sm11024953qkg.91.2021.04.13.13.15.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Apr 2021 13:15:37 -0700 (PDT) Date: Tue, 13 Apr 2021 16:15:35 -0400 From: Peter Xu To: Axel Rasmussen Cc: Alexander Viro , Andrea Arcangeli , Andrew Morton , Hugh Dickins , Jerome Glisse , Joe Perches , Lokesh Gidra , Mike Kravetz , Mike Rapoport , Shaohua Li , Shuah Khan , Stephen Rothwell , Wang Qing , linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Brian Geffon , "Dr . David Alan Gilbert" , Mina Almasry , Oliver Upton Subject: Re: [PATCH v2 7/9] userfaultfd/selftests: reinitialize test context in each test Message-ID: <20210413201535.GD4440@xz-x1> References: <20210413051721.2896915-1-axelrasmussen@google.com> <20210413051721.2896915-8-axelrasmussen@google.com> MIME-Version: 1.0 In-Reply-To: <20210413051721.2896915-8-axelrasmussen@google.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 3DE84E4 X-Stat-Signature: hqw1cwo761hhwp5iz3scjg3d9wuhapdz Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf29; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=216.205.24.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618344941-984747 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: On Mon, Apr 12, 2021 at 10:17:19PM -0700, Axel Rasmussen wrote: > Currently, the context (fds, mmap-ed areas, etc.) are global. Each test > mutates this state in some way, in some cases really "clobbering it" > (e.g., the events test mremap-ing area_dst over the top of area_src, or > the minor faults tests overwriting the count_verify values in the test > areas). We run the tests in a particular order, each test is careful to > make the right assumptions about its starting state, etc. > > But, this is fragile. It's better for a test's success or failure to not > depend on what some other prior test case did to the global state. > > To that end, clear and reinitialize the test context at the start of > each test case, so whatever prior test cases did doesn't affect future > tests. > > This is particularly relevant to this series because the events test's > mremap of area_dst screws up assumptions the minor fault test was > relying on. This wasn't a problem for hugetlb, as we don't mremap in > that case. > > Signed-off-by: Axel Rasmussen > --- > tools/testing/selftests/vm/userfaultfd.c | 221 +++++++++++++---------- > 1 file changed, 127 insertions(+), 94 deletions(-) > > diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c > index 1f65c4ab7994..0ff01f437a39 100644 > --- a/tools/testing/selftests/vm/userfaultfd.c > +++ b/tools/testing/selftests/vm/userfaultfd.c > @@ -89,7 +89,8 @@ static int shm_fd; > static int huge_fd; > static char *huge_fd_off0; > static unsigned long long *count_verify; > -static int uffd, uffd_flags, finished, *pipefd; > +static int uffd = -1; > +static int uffd_flags, finished, *pipefd; > static char *area_src, *area_src_alias, *area_dst, *area_dst_alias; > static char *zeropage; > pthread_attr_t attr; > @@ -342,6 +343,121 @@ static struct uffd_test_ops hugetlb_uffd_test_ops = { > > static struct uffd_test_ops *uffd_test_ops; > > +static int userfaultfd_open(uint64_t *features) > +{ > + struct uffdio_api uffdio_api; > + > + uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK); Keep UFFD_USER_MODE_ONLY? [...] > @@ -961,10 +1045,9 @@ static int userfaultfd_zeropage_test(void) > printf("testing UFFDIO_ZEROPAGE: "); > fflush(stdout); > > - uffd_test_ops->release_pages(area_dst); > - > - if (userfaultfd_open(0)) > + if (uffd_test_ctx_clear() || uffd_test_ctx_init(0)) > return 1; Would it look even nicer to init() at the entry of each test, and clear() after finish one test? > + > uffdio_register.range.start = (unsigned long) area_dst; > uffdio_register.range.len = nr_pages * page_size; > uffdio_register.mode = UFFDIO_REGISTER_MODE_MISSING; The rest looks good to me. Thanks, -- Peter Xu