Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp989684pxb; Thu, 15 Apr 2021 11:04:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+Uvfxjec339+Lm3vuE3cFXVVs9FbeZRuv7rUFn3c9p/MSyV8o5m10+46bpqz3sP/cCIOH X-Received: by 2002:a17:90a:bb94:: with SMTP id v20mr5147146pjr.144.1618509895923; Thu, 15 Apr 2021 11:04:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618509895; cv=none; d=google.com; s=arc-20160816; b=m01nOpjDPL5hbNZmQ8ysxRmCSvnJI/yPLvR4jjUnwsfAf/CIASxkPqK7gyaFPry7Gx 0BHIHf0Uvz9k6knrao3KveBJftg8xc1RVhc5qsN3eE+VrE1yj5apphgu//xmMoOr+Urf Pu1npI7mv4QZmNkZnbeAyerT8txIMyqafbqiHwPqdEiKnQsyT2Fb/irjkqSCEeuNwq8H tztBwxquQ64DPL0jw7rya8GR3Sb4bgrcRf66tsE/pG840GybSNjnxumkNrtnAQ2vivoB gLf7IAh9BAc2uuunt3qKBuUmpmRNsTHLUIugI//nEum3QCLk8oWHuWE1YONyEmNz7umc qI7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=jMi3JQh4ceVfV/j7Lf7DWzkm4A/CG7sUwuBKTI9Y7vs=; b=oIYFTi+Sgo5zOuMo/K8LQsUp6xO+o/M35vMxuXNWy7q9qczLpo6wiV6gR2Q8vxaPeF 8EZNrGM6W+zqD9Chf6PzqEOdfdVhTyoe3xncfeFSR5wLvCjke0ldcEA1EZZ9+2EpvG7i zVx51rpmyQaa0pAUOpCcsF8lRSrSRpsBvINkUCue27Ma8AQnM5Pe4ZKuNNQK9Z3pNUta y+PmYlVCWbbxzJfvsc2kniJAo0VCfNR1RzIdF6RNjxGoV1KkI+orVU53BLhpWHI84EtU p30rvQj34Th3pkWVd1bzU7yLW1JvnKMHsJifsPUJRzmvjy7ts1R5ieCKkhMQ0eU2q1Ay Cfng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LOWfqGRg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e6si3962031pls.73.2021.04.15.11.04.43; Thu, 15 Apr 2021 11:04:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LOWfqGRg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S234573AbhDOSER (ORCPT + 99 others); Thu, 15 Apr 2021 14:04:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233134AbhDOSEQ (ORCPT ); Thu, 15 Apr 2021 14:04:16 -0400 Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 935D1C061760 for ; Thu, 15 Apr 2021 11:03:52 -0700 (PDT) Received: by mail-il1-x131.google.com with SMTP id j12so7028831ils.4 for ; Thu, 15 Apr 2021 11:03:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jMi3JQh4ceVfV/j7Lf7DWzkm4A/CG7sUwuBKTI9Y7vs=; b=LOWfqGRgHZ2GaLk4r0jnjtm6hmUQDMtLwyD23G/zSp+dciXK8p9hxW5dpWlieJWVov 9fZxBC9Gq0vChe5/SI2Xz2rZtf5evjuecN76OfNiPb1n7JvJtsnyuPbcU7lyolclN6h9 xm/USSXnuwH42Jp23W8TX1U8yNA3aiVNF0zBR+WhMg086kxGgjnkrWSXlZ2K1t+dKvX5 mz6u4JCxYhvmR84+sH+l+BSsbQc2DhNnetCk62Xcxyf/eFiJ8bkw8HN++VM57h/YDUKu p8uMAQs2++W6WuNhOtTfjydZwv7nX0X3/sjt3phwy8sk76atjR1aN3znqw1PgpCPveT8 oH7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jMi3JQh4ceVfV/j7Lf7DWzkm4A/CG7sUwuBKTI9Y7vs=; b=GBIbTMeqMxXV6ih/tD0/HLZsCbJTxkghm/hvfTCpGnSlWNWEDmjP6cNtvJUyObiqme 3EK1fJ5kWcB67nVjupjCzJIUVuhyILBCN27p0hyprK6gcFgznAEN26G/rZWlugmhNPqC f+aw3frrMhMq9m4EVdBjZ/3YXpYHi2Gn1NB9wiCNbVvaEv5/0qvDWK9EicSgy3q87o5N qD6CEpUJLAXQFEdZLwXAKsrGCV8aVnsSLypLvd6YAW5VFXttfNX7tG88OLpFd3dbw9D0 O/+U/ndo6WJ14qjbcGBnNO3euRQczVHSZWd9MxzzrUhEUsFQrL0c41pwBEylc+ggZaeU ff8A== X-Gm-Message-State: AOAM5301D9ht7fKVzpGJucGE4pklO6qfyafLAd6SPaH/fap2wg+K5RPT MBIt+vVHRU+PCkoxs0roomvrfsB/TixVWRPn/25hxg== X-Received: by 2002:a05:6e02:1d06:: with SMTP id i6mr1346852ila.165.1618509831881; Thu, 15 Apr 2021 11:03:51 -0700 (PDT) MIME-Version: 1.0 References: <20210413051721.2896915-1-axelrasmussen@google.com> <20210413051721.2896915-8-axelrasmussen@google.com> <20210413201535.GD4440@xz-x1> In-Reply-To: <20210413201535.GD4440@xz-x1> From: Axel Rasmussen Date: Thu, 15 Apr 2021 11:03:14 -0700 Message-ID: Subject: Re: [PATCH v2 7/9] userfaultfd/selftests: reinitialize test context in each test To: Peter Xu 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, LKML , linux-kselftest@vger.kernel.org, Linux MM , Brian Geffon , "Dr . David Alan Gilbert" , Mina Almasry , Oliver Upton Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 13, 2021 at 1:15 PM Peter Xu wrote: > > 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? I slightly prefer clearing at the beginning, as it means we don't need to depend on the previous test being correct for this test to function. And, we don't need more complex error handling in the test cases to make sure we don't mess things up for the next test. But, two things we can do to clean this up as-is: The initialization function can just call clear itself, so tests don't need to worry about it. And, with err(), we don't need these functions to return an int any more. I'll send a version like that, we can see how it looks. > > > + > > 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 >