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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74DBFCCA47B for ; Tue, 14 Jun 2022 19:25:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243622AbiFNTZO (ORCPT ); Tue, 14 Jun 2022 15:25:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240962AbiFNTZM (ORCPT ); Tue, 14 Jun 2022 15:25:12 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6F8E921E1D for ; Tue, 14 Jun 2022 12:25:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655234710; 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=m1JgHuVxzVW3EUm2DTV344V5KoB3ftgRF+8dYijCj7E=; b=OZSMXpNwul8OyzzikAUgP8nvfEMDx9/luvbGxQhC2p6G21Sfg9Kc8x4Sb7MZ726ERGVVlM dxd0eKCBUgeXLuz27/a7tm+EVua6KqXQx8t6CE4qEnzIzhnvuAzzqv82kSCAwB6pX++OMq CZ86jSxehk1Q2PHyQ8MTgPPz6t2Bqmo= Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-19-GI3WTPhrOjeANXasvux6vw-1; Tue, 14 Jun 2022 15:25:09 -0400 X-MC-Unique: GI3WTPhrOjeANXasvux6vw-1 Received: by mail-io1-f69.google.com with SMTP id i126-20020a6bb884000000b006691e030971so4806691iof.15 for ; Tue, 14 Jun 2022 12:25:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=m1JgHuVxzVW3EUm2DTV344V5KoB3ftgRF+8dYijCj7E=; b=HTQTU5lSXbnui0QEKbHemulV+irFW7BMdcHJ1YB9yXFdWdiBvPhEkMTc0Lfo5yTAWd dcyV7txl9rLRnbwpUr28blNOfVv5RL5PKTFrImTdR8AVu02igrE81My488JZ8+yCE75t CYX2cDXeaybCesBqUFr4Kf7vo3Rjt50AeG1IhzGavkUV2+hQecH3+WMCj+5vlUN2QggO 5mqzt34sKgIGFXNFDrNO3nmphpsn3yGLuMYal5RfyEhYW8yWH+2+tyi70FrZeas0TdhA lpCcCZrWAz6vA5kcrBocEpF8qeOnSstpfzNrbOoHAWZ7xpLU43BbVHWWYPBDN8X2AyL+ 1LSA== X-Gm-Message-State: AJIora+8IJR19U/0TtfphDQiVpVbjEm481hgoDHseE+4nNF8YmXr3I4x t2UcBnovQfbLB9FmLB5FvVzwd9v+X4G6TLnilP+yES5EUPCqivGhqAc3acTRdExxaW6dYqJ6NTC o6YN/YNSWchPFv10Af6vR X-Received: by 2002:a05:6e02:156e:b0:2d1:c265:964f with SMTP id k14-20020a056e02156e00b002d1c265964fmr3980760ilu.153.1655234708491; Tue, 14 Jun 2022 12:25:08 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vTulct6ZXQrXPJZkpnJj5uihhZfw46xRlX5sgpH1UyYv+ABqvggEeyigrm4fGfeHXqmfuynA== X-Received: by 2002:a05:6e02:156e:b0:2d1:c265:964f with SMTP id k14-20020a056e02156e00b002d1c265964fmr3980749ilu.153.1655234708266; Tue, 14 Jun 2022 12:25:08 -0700 (PDT) Received: from xz-m1.local (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id y11-20020a02904b000000b0032e6f0d3796sm5206324jaf.145.2022.06.14.12.25.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 12:25:07 -0700 (PDT) Date: Tue, 14 Jun 2022 15:25:04 -0400 From: Peter Xu To: Axel Rasmussen 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 , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , zhangyi , linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH v3 3/6] userfaultfd: selftests: modify selftest to use /dev/userfaultfd Message-ID: References: <20220601210951.3916598-1-axelrasmussen@google.com> <20220601210951.3916598-4-axelrasmussen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220601210951.3916598-4-axelrasmussen@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org On Wed, Jun 01, 2022 at 02:09:48PM -0700, 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 | 37 +++++++++++++++++++++--- > 1 file changed, 33 insertions(+), 4 deletions(-) > > diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c > index 0bdfc1955229..1badb5d31bf9 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; > @@ -154,12 +157,14 @@ static void usage(void) > ret, __LINE__); \ > } while (0) > > -#define err(fmt, ...) \ > +#define errexit(exitcode, fmt, ...) \ > do { \ > _err(fmt, ##__VA_ARGS__); \ > - exit(1); \ > + exit(exitcode); \ > } while (0) > > +#define err(fmt, ...) errexit(1, fmt, ##__VA_ARGS__) > + > static void uffd_stats_reset(struct uffd_stats *uffd_stats, > unsigned long n_cpus) > { > @@ -383,13 +388,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(); I can understand uffd is a global var, but still AFAICT that's trivially easy to do the return to match the syscall case.. uffd = __userfaultfd_open_dev(); And since at it, it'll be great to make a macro: #define UFFD_FLAGS (O_CLOEXEC | O_NONBLOCK | UFFD_USER_MODE_ONLY) Thanks, > + else > + uffd = syscall(__NR_userfaultfd, > + O_CLOEXEC | O_NONBLOCK | UFFD_USER_MODE_ONLY); > if (uffd < 0) > - err("userfaultfd syscall not available in this kernel"); > + errexit(KSFT_SKIP, "creating userfaultfd failed"); > uffd_flags = fcntl(uffd, F_GETFD, NULL); > > uffdio_api.api = UFFD_API; > @@ -1691,6 +1714,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(); > } > > -- > 2.36.1.255.ge46751e96f-goog > -- Peter Xu