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 35818C433EF for ; Thu, 19 May 2022 17:57:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 785F66B0071; Thu, 19 May 2022 13:57:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 70DAD6B0072; Thu, 19 May 2022 13:57:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5AF4C6B0073; Thu, 19 May 2022 13:57:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 464EE6B0071 for ; Thu, 19 May 2022 13:57:10 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 15C0033A49 for ; Thu, 19 May 2022 17:57:10 +0000 (UTC) X-FDA: 79483249020.04.94E1609 Received: from mail-io1-f45.google.com (mail-io1-f45.google.com [209.85.166.45]) by imf22.hostedemail.com (Postfix) with ESMTP id 4C01DC00DC for ; Thu, 19 May 2022 17:57:07 +0000 (UTC) Received: by mail-io1-f45.google.com with SMTP id a10so6548440ioe.9 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=MGDtQpXkq8VgsnfEBFksF3dU/xQVoLc6dmyXJav5pHFLbLEznqcbs/Bnrbwex78NNi HnCS5ZNJAjjE+U8bd/OAwS08DxkpbHKySaU8b2ddz28Fhs9Ej0b3pQJYouo2W8TtJkyR zB51XnP81FFWIU5uISXZHlv2cVos7K+oKvhrrg20lzmwUWqQDzOpHIy4jxAWSSGTEZfe c21BolPQknd93epmJ4iPm9S00bT/5igZEEVx1SIO2O12xZpBUhlUwHKYIwcvgyyZqHs7 cStKFMU1zBwNy+prFA7WjUGD/WTkcggLC/GWNqFLUqZ9KloV9DBG25NhLyZK2H6OrgLP +91w== X-Gm-Message-State: AOAM531Fg/nQ6o5AlM+0lUZnMzOSCJ72RfvNd9B0gRjhdHxf9Olfryjl GWCDJq/8RTzS3vSb1dWNFoe5dWyNCftAFQSiWbddqA== X-Google-Smtp-Source: ABdhPJxLnLPad++snwSrGlFPy2lO2WAmvA7axVeAQ6DyfojYPDblWdyjk16yhcxDogtbfCy3V2mwhAIveq3XhTsBM0Y= 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-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 4C01DC00DC Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=j3Limxuh; spf=pass (imf22.hostedemail.com: domain of axelrasmussen@google.com designates 209.85.166.45 as permitted sender) smtp.mailfrom=axelrasmussen@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Stat-Signature: 5bzjcyzs46smybs7nbd9aqdnetampie1 X-HE-Tag: 1652983027-342637 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 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