Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2095484iob; Fri, 20 May 2022 01:42:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySVqwE44wPOTCIHOLvB/eedmt/DzOUgn9G5Q12PHVuTgY180TaRMwfC9s6CC0lWGcRz8V1 X-Received: by 2002:a17:90b:4f48:b0:1df:e20c:cbc1 with SMTP id pj8-20020a17090b4f4800b001dfe20ccbc1mr6172309pjb.3.1653036141965; Fri, 20 May 2022 01:42:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653036141; cv=none; d=google.com; s=arc-20160816; b=OxF7Fe5Xg3DZGQB3Aif08J6DJm9pe4o0zWnNS9mxQtZfllNB4IXFFhiaW8VJMmqGCk C9Pc8na6rUaq+BCVj+UAKQgxrteRq+zctxc1Jknvv91Q1fyl70mDQfOziPs7x6Qf74rJ Mrb0H+OM5SghjwvRnMwIRf9o+36GuzTIiPGbQGiSpzUlrFmrOOaCgLy29JvJIkgYEz4E 2H1gaO2tOl3FULhOFRYhjWlaz3YobahZVsH/jrg7hPKnRYzRNHvZea0gMjdkLQSiPUhb /KbuOQYJPKecrUthPeOlJDL/I7ZVkszP525WwhxIOVUTjMMiu3kIitHYlHvR8UBEKZp5 Yh8w== 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=nTvwJwfDzauPQ+of5JXtLLkQatXip/21hHhzryuEKQA=; b=jEBFnM9Fv9AvhaJqk7tO24Ucrp7y8mODJozR44W3eiKOQuYiWiKWZ2yqQH2ITwsmGN opPRdepkZlDtRsD+FCEm8AU22NBymd/1iOkaijftjDnZsx2RWGq0e9izB5flgb1cOU+i DNhJdOFBxCJggUUb+zHVOZXAgo13eYbpL6en5bz+kAq9KMP4y9UwtPWFiiVdf0J3HkI1 l6gurkdKUP2e+LzZ8TiB6L2pxnqrIJ0VTryNPFpSXSfjR8/MeNqNgRLynbDo3diDh6sJ 6RkTfEQNxqWlCN0VMy0QkOX3wssUdeu1ua50XxMvsikc8Q/xsKnTcuiHkhJ8rNtjjuRG V/Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=j3Limxuh; 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 x3-20020a170902ec8300b00153ce7c9244si1635572plg.97.2022.05.20.01.42.09; Fri, 20 May 2022 01:42:21 -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=20210112 header.b=j3Limxuh; 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 S241499AbiESR5R (ORCPT + 99 others); Thu, 19 May 2022 13:57:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234458AbiESR5K (ORCPT ); Thu, 19 May 2022 13:57:10 -0400 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88229CEBB6 for ; Thu, 19 May 2022 10:57:09 -0700 (PDT) Received: by mail-io1-xd31.google.com with SMTP id p74so2928229iod.8 for ; Thu, 19 May 2022 10:57:09 -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=nTvwJwfDzauPQ+of5JXtLLkQatXip/21hHhzryuEKQA=; b=j3LimxuhjsDMbf3h7pgM2pWwYSD4AVDqwr9ip1QCctj49RKDncQaqTHeIyXLl50zzU 4LG3je7shHcDY1r8jzTsxpcHjD9pp0lfGzlQqhuk55gzgWRRU5pqfxpRJbcJFKW03pa3 LLtD7ehpQwpgyXa+eY0hUTZk4ioiKf7glMqpvtARWpYoJpPWD8StCBp85+mKbJnmGOEO TBKLipGuUQdEgRWPXm1GzIGIFeMe5N0+DDsTrPgxpZj900S2UeEVlLAND2cbavGFIQGt CTjt5zWmLaAZRopYq3odW6ZOoq4jz7+VypCEx0y6zLBALPoGbIsN3k2WOTSsu3sefi7x DLGQ== 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=nTvwJwfDzauPQ+of5JXtLLkQatXip/21hHhzryuEKQA=; b=EzoVKP+WcGUw28xU/OztboPwgEQJ1zgIYOIrWAbj7ky97TlfnDOdRsWK/DjZ8u2HRR 2bbNSKY/0xM1F2fO+8ACKFHUyZ/6xlIolKcv3Jwyl2aUQiEb2emmK3WnUe01ccg6zzFF AfeeJeLLqxCTZU23TznwHWn+tRVQ7Mtgkk60ipnSNfLA7yP/Y1Eo6G/d9qI8wCuo9mH+ EhuTahpQo5EVsQ+6nAx9IURpMt+fdL3tYg6iQ3/jfKjPHdunvbjB37CnhXko4aFoxSTp SstqRJuWVidI/wC6jEw8ezq61jCdl46mBCt41PxYYm/14/8b3+wJ8HS3/CTN7zUGeXfQ Q7vQ== X-Gm-Message-State: AOAM531FZVBztU+FnPREK7IxoBCcotX8BoS9YHEWVq7dCpO3DZcvFyv9 3KGDcCTsvIQB+ZL6zvqojRvlBxrpgI4q2kMQe8Nq0w== X-Received: by 2002:a5d:94c2:0:b0:60b:bd34:bb6f with SMTP id y2-20020a5d94c2000000b0060bbd34bb6fmr3044953ior.32.1652983028426; Thu, 19 May 2022 10:57:08 -0700 (PDT) MIME-Version: 1.0 References: <20220422212945.2227722-1-axelrasmussen@google.com> <20220422212945.2227722-4-axelrasmussen@google.com> In-Reply-To: From: Axel Rasmussen Date: Thu, 19 May 2022 10:56:32 -0700 Message-ID: Subject: Re: [PATCH v2 3/6] userfaultfd: selftests: modify selftest to use /dev/userfaultfd To: Shuah Khan Cc: Alexander Viro , Andrew Morton , Charan Teja Reddy , Dave Hansen , "Dmitry V . Levin" , Gleb Fotengauer-Malinovskiy , Hugh Dickins , Jan Kara , Jonathan Corbet , Mel Gorman , Mike Kravetz , Mike Rapoport , Nadav Amit , Peter Xu , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , zhangyi , linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, LKML , Linux MM , Linuxkselftest Content-Type: text/plain; charset="UTF-8" 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, Apr 26, 2022 at 9:16 AM Shuah Khan wrote: > > On 4/22/22 3:29 PM, Axel Rasmussen wrote: > > We clearly want to ensure both userfaultfd(2) and /dev/userfaultfd keep > > working into the future, so just run the test twice, using each > > interface. > > > > Signed-off-by: Axel Rasmussen > > --- > > tools/testing/selftests/vm/userfaultfd.c | 31 ++++++++++++++++++++++-- > > 1 file changed, 29 insertions(+), 2 deletions(-) > > > > diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c > > index 92a4516f8f0d..12ae742a9981 100644 > > --- a/tools/testing/selftests/vm/userfaultfd.c > > +++ b/tools/testing/selftests/vm/userfaultfd.c > > @@ -77,6 +77,9 @@ static int bounces; > > #define TEST_SHMEM 3 > > static int test_type; > > > > +/* test using /dev/userfaultfd, instead of userfaultfd(2) */ > > +static bool test_dev_userfaultfd; > > + > > /* exercise the test_uffdio_*_eexist every ALARM_INTERVAL_SECS */ > > #define ALARM_INTERVAL_SECS 10 > > static volatile bool test_uffdio_copy_eexist = true; > > @@ -383,13 +386,31 @@ static void assert_expected_ioctls_present(uint64_t mode, uint64_t ioctls) > > } > > } > > > > +static void __userfaultfd_open_dev(void) > > +{ > > + int fd; > > + > > + uffd = -1; > > + fd = open("/dev/userfaultfd", O_RDWR | O_CLOEXEC); > > + if (fd < 0) > > + return; > > + > > + uffd = ioctl(fd, USERFAULTFD_IOC_NEW, > > + O_CLOEXEC | O_NONBLOCK | UFFD_USER_MODE_ONLY); > > + close(fd); > > +} > > + > > static void userfaultfd_open(uint64_t *features) > > { > > struct uffdio_api uffdio_api; > > > > - uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK | UFFD_USER_MODE_ONLY); > > + if (test_dev_userfaultfd) > > + __userfaultfd_open_dev(); > > + else > > + uffd = syscall(__NR_userfaultfd, > > + O_CLOEXEC | O_NONBLOCK | UFFD_USER_MODE_ONLY); > > if (uffd < 0) > > - err("userfaultfd syscall not available in this kernel"); > > + err("creating userfaultfd failed"); > > This isn't an error as in test failure. This will be a skip because of > unmet dependencies. Also if this test requires root access, please check > for that and make that a skip as well. Testing with the userfaultfd syscall doesn't require any special permissions (root or otherwise). But testing with /dev/userfaultfd will require access to that device node, which is root:root by default, but the system administrator may have changed this. In general I think this will only fail due to a) lack of kernel support or b) lack of permissions though, so always exiting with KSFT_SKIP here seems reasonable. I'll make that change in v3. > > > uffd_flags = fcntl(uffd, F_GETFD, NULL); > > > > uffdio_api.api = UFFD_API; > > @@ -1698,6 +1719,12 @@ int main(int argc, char **argv) > > } > > printf("nr_pages: %lu, nr_pages_per_cpu: %lu\n", > > nr_pages, nr_pages_per_cpu); > > + > > + test_dev_userfaultfd = false; > > + if (userfaultfd_stress()) > > + return 1; > > + > > + test_dev_userfaultfd = true; > > return userfaultfd_stress(); > > } > > > > > > thanks, > -- Shuah