Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3152951pxb; Tue, 21 Sep 2021 16:07:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTLZXRKFHvX9P37Jqdz62YRN0j4u6s0d1p4PynH0oROhTw1bSNZ7gA+xkNgHYSgRTpgQzt X-Received: by 2002:a50:cf03:: with SMTP id c3mr29809668edk.236.1632265649862; Tue, 21 Sep 2021 16:07:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632265649; cv=none; d=google.com; s=arc-20160816; b=wES5bXn24IV4SeEnspso3gaeb1oaqmUagKS1YI4QYJLLZqVKDAaFY+4D/jJ3PIoRCS zRiCYt84BlAxwmnJ2FWAO0vXlZb2AJia0ZOnYyrMR7gdLJ/vvLIbuFYj3zA0nxEL1b4r hlWbQ+3Loxf4IN6ricA9K0zcBP7OR1oX29nmDsc08A9VdGu5oqnzLZyN3q3Iq0YLleGn puzqjLw75mQHQNnnjRT7E5vZo/uScmYP509DfJmcFJ+pcI6k6cYowsQNI9pZMtWi0evd S4sVo3iYLfjZJN0ZSWTMWzfzYX8YBxNyDAqhsZTwIOLp6UXu/S3H4CyNcoVp1f/wRsFi bKNg== 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=DqY1Vo6rBjxwgRtTp30JVZpZOPnNe0pyZj0C2CZjUVw=; b=puWvNsh/iYkAp5lj8N2WANyQeMwNZCRZPG39P+ioWK8VNhFuCulJIizzPf8SdAVWT6 ZLqq7k1c4Wuye+llQkSxqiIhnGS4vvf4yZHyVNcXSPHW2sW//J2R2GZSrzXM4VznvDo5 cUsmWwbG6F+W+Nn3Dv7UpCr0nlNZrhSFrmqXUXYwDsZXXNoy/6ecOpsF6prb0wzexRu1 jV0ERH+VjQvQdY1vlq5pWZuEdUxO+EKkK7QZH45d33QtMCIG3kRNnrL+cKdfdzKy54AV g33rQCVaBc47M3U3LWcksE4Ox7UXOUnMwojwKxkwmIb8Gfq8fCtIbOBfvHNOtWZ7gwtl C7ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=s0cRXLXP; 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 y21si443896edl.278.2021.09.21.16.06.59; Tue, 21 Sep 2021 16:07:29 -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=20210112 header.b=s0cRXLXP; 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 S229912AbhIUUdT (ORCPT + 99 others); Tue, 21 Sep 2021 16:33:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234860AbhIUUdS (ORCPT ); Tue, 21 Sep 2021 16:33:18 -0400 Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F500C061574 for ; Tue, 21 Sep 2021 13:31:49 -0700 (PDT) Received: by mail-il1-x12f.google.com with SMTP id a20so193722ilq.7 for ; Tue, 21 Sep 2021 13:31:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DqY1Vo6rBjxwgRtTp30JVZpZOPnNe0pyZj0C2CZjUVw=; b=s0cRXLXPw9jzQRveUiI1hg8xKNbO9dZyF2j+462NYaizVy6T8uCV4/hjprvYfdzWoK r8HUEPyj0WrjpFykalEkeT/7dDkaocbHBiT2BZinKxnDQFMeUk53wGxO+Co0J9kxk6Jt oSEf4JD0TCudSACXdHtE03OK1CPUU/fEHrUOkdw30QlzhQIejrA+w8Kp3eqlCXBlfkps FXYuGnR774tuVhqaT5so2vdhgli8oMSgpIG23ZA2UdgKnLBh3yp4YnGv7homD1JeRmPk 4f0hAgQ7rseaAk2efIoej5cChF6dVIwvmRcTOx9vpxtkWFOBFc+qJfDefVwHQb8kV054 l5rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DqY1Vo6rBjxwgRtTp30JVZpZOPnNe0pyZj0C2CZjUVw=; b=QmYe5dCTts22ez5df5iDyVuGcqXS9fifBhxQjIcjwfJic8qX6xRpculcOYNjD7tTkY ABJc8a4WXIOnfby9XKQ/Mw1XqYzQA59ZqfUZfUer7ui2lc2njbAbGpiZc9mkuX+CTQLq vg1BxvHnpyFSpx3ZuO6KLo8gU8fput/cm5N7uIaNpmlx7ualpU7qe87ugSqcrQogiPKS o8FtB9UG+B9DYyT0eQQEJgNF3pAM+UeRb4XMrcU6X5AGye6Y4qUzDMi8hOlgEaDOAOcb xaoKG6NrHpvSHRTM8WWLuHa7D65N/nL/COHfVNaCcMBvJ9n0xZf4kmuM1x2L1TjiJpWm gPxA== X-Gm-Message-State: AOAM53279c9oAVNHh+vcqvKgeP1mh2ukrWMBEMTgKoS+vJ0nKN+/A1dj 6VDh52/hBx9Zj8uR0Yyr/WaCAKQKQfb9OVPN8IIAlQ== X-Received: by 2002:a92:de07:: with SMTP id x7mr23230621ilm.239.1632256308713; Tue, 21 Sep 2021 13:31:48 -0700 (PDT) MIME-Version: 1.0 References: <20210921163323.944352-1-axelrasmussen@google.com> In-Reply-To: From: Axel Rasmussen Date: Tue, 21 Sep 2021 13:31:12 -0700 Message-ID: Subject: Re: [PATCH 1/3] userfaultfd/selftests: fix feature support detection To: Peter Xu Cc: Andrew Morton , Shuah Khan , Linux MM , Linuxkselftest , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 21, 2021 at 12:21 PM Peter Xu wrote: > > On Tue, Sep 21, 2021 at 11:26:14AM -0700, Axel Rasmussen wrote: > > On Tue, Sep 21, 2021 at 10:44 AM Peter Xu wrote: > > > > > > Hi, Axel, > > > > > > On Tue, Sep 21, 2021 at 09:33:21AM -0700, Axel Rasmussen wrote: > > > > diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c > > > > index 10ab56c2484a..2366caf90435 100644 > > > > --- a/tools/testing/selftests/vm/userfaultfd.c > > > > +++ b/tools/testing/selftests/vm/userfaultfd.c > > > > @@ -79,10 +79,6 @@ static int test_type; > > > > #define ALARM_INTERVAL_SECS 10 > > > > static volatile bool test_uffdio_copy_eexist = true; > > > > static volatile bool test_uffdio_zeropage_eexist = true; > > > > -/* Whether to test uffd write-protection */ > > > > -static bool test_uffdio_wp = false; > > > > -/* Whether to test uffd minor faults */ > > > > -static bool test_uffdio_minor = false; > > > > > > IMHO it's not a fault to have these variables; they're still the fastest way to > > > do branching. It's just that in some cases we should set them to "false" > > > rather than "true", am I right? > > > > > > How about we just set them properly in set_test_type? Say, we can fetch the > > > feature bits in set_test_type rather than assuming it's only related to the > > > type of memory. > > > > We could do that, but it would require opening a userfaultfd, issuing > > a UFFDIO_API ioctl, and getting the feature bits in set_test_type. And > > then I guess just closing the UFFD again, as we aren't yet setting up > > for any particular test. To me, it seemed "messier" than this > > approach. > > > > Another thing to consider is, for the next patch we don't just want to > > know "does this kernel support $FEATURE in general?" but also "is > > $FEATURE supported for this particular memory region I've > > registered?", and we can't have a single global answer to that. > > Could I ask why? For each run, the memory type doesn't change, isn't it? Then > I think the capability it should support is a constant? Ah, it has to do with us asserting the list of expected ioctls. The kernel changes the list of ioctls it reports in response to a UFFDIO_REGISTER, depending on the particular kind of vma being registered, **as well as what mode(s) it is being registered with**. So for example, consider the hugetlb_shared test. When registering, the kernel might set the UFFDIO_CONTINUE bit or not, depending on whether we registered with the MINOR mode bit set in particular. So it will be present in one test case, but not in another, and so the set of expected ioctls has to be computed at test time, rather than in set_test_type. > > Btw, note that "open an uffd, detect features, close uffd quickly" during setup > phase is totally fine to me just for probing the capabilities, and instead of > thinking it being messy I see it a very clean approach.. > > > It seemed a bit cleaner to me to write the code as if I was dealing with that > > case, and then re-use the infrastructure I'd built for patch 2/3. > > I didn't comment on patch 2, but I had the same confusion - aren't all these > information constant after we settle the hardware, the kernel and the memory > type to test? > > > > > Basically, I didn't initially have a goal of getting rid of these > > variables, but it ended up being the cleanest way (IMHO). > > > > Just trying to explain the thinking. :) In the end, I think it's a > > stylistic choice and don't feel super strongly about it, either way > > could work. So, I can change it if you or others do feel strongly. > > I have no strong opinion as long as the code works (which I trust you on :). > We can keep it in Andrew's queue unless you do feel the other way is better. > > Thanks, > > -- > Peter Xu >