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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED3C5C43334 for ; Tue, 14 Jun 2022 19:25:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 621446B0071; Tue, 14 Jun 2022 15:25:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D03E6B0072; Tue, 14 Jun 2022 15:25:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4709E6B0073; Tue, 14 Jun 2022 15:25:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 397EF6B0071 for ; Tue, 14 Jun 2022 15:25:11 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0A2502089E for ; Tue, 14 Jun 2022 19:25:11 +0000 (UTC) X-FDA: 79577819622.24.2599016 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf28.hostedemail.com (Postfix) with ESMTP id A1DFBC00AB for ; Tue, 14 Jun 2022 19:25:10 +0000 (UTC) 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-il1-f199.google.com (mail-il1-f199.google.com [209.85.166.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-517-kRRjoBzCOVOFTAYLBskz4A-1; Tue, 14 Jun 2022 15:25:09 -0400 X-MC-Unique: kRRjoBzCOVOFTAYLBskz4A-1 Received: by mail-il1-f199.google.com with SMTP id b11-20020a92340b000000b002d3dbbc7b15so7160189ila.5 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=yqs6qiQcy4U4D42HqGNQupEyLJbGurkyy+H5lmaxkBdcC6CFhSjDOyL6NvcDmj2DtA 2aqW9OpKns5wRYusqTn4H2DYT/sY7RH9DY99KS9N/eDXOfilKWg120F4TnITLcmXZXqG vqiWbVCs6X4BlAWj2FKZiBEC/ZQV/CKT6nmCl3DFOmNEWSjbdtX76t0zul4xu51XZJxq amqaLIb/tZAYoFI5cgApWndraPrSXMl2uGBw9rPh0R82oVnOxzAR/TQhdijQ4kLUB8mY dGi7pU6hh8JVqPRsCNDL9sokdZmGxldudy07IqQfwwpDEk36HMpJtKZkYllDIhQ+nNB0 Ykig== X-Gm-Message-State: AJIora9fniLDg530FMCNESK3ptVWgJTovJooOfkQdOk04tyDAx3Y5/zX 55LcIGMx7/uTct2xGxCVvNAmwvxeZfsx4SUT3EoSC3I7gcGXXgqygCKGZ54rHfJSETdnbq3vPWe 9RFFZ8aFn0SQ= X-Received: by 2002:a05:6e02:156e:b0:2d1:c265:964f with SMTP id k14-20020a056e02156e00b002d1c265964fmr3980769ilu.153.1655234708496; 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 In-Reply-To: <20220601210951.3916598-4-axelrasmussen@google.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655234710; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=m1JgHuVxzVW3EUm2DTV344V5KoB3ftgRF+8dYijCj7E=; b=g6gYiXe8nPNczjouKcCHD6Mvh27YzoPN4sgo6+ba0l8B8v568IIeAeiFWHyvU7odWoEgxk vKMrpbmD8QUxmHmG/nDQpPrKzIWu7KocxkVFDbHuJqgOrzqFN7d8Hs87lBQSNMlMM2S5KD YOOVUXJtpLH2I0cFKGQVlb/1xyfZMCQ= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OZSMXpNw; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf28.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655234710; a=rsa-sha256; cv=none; b=R3Fh/FNYcbzpgMy6OF3ypeszyCm68P46mBvehDyUa5xpUiW1sSkfCRlokb/e2ukdKyzEcE PLAAM3rHtHWad0iyx+tBa2xn9u55uSVqXMcg2hbtX2VOUZXZCKg5RDt3A/tWw4el6sc8On 9NVEZvF5ZAF63gs5tl9S5UQJiBzrcu0= X-Stat-Signature: dd8rd6mz7tqq4tag668xtfubdzxotuzs X-Rspamd-Queue-Id: A1DFBC00AB X-Rspam-User: X-Rspamd-Server: rspam05 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=OZSMXpNw; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf28.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=peterx@redhat.com X-HE-Tag: 1655234710-517211 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 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