From patchwork Wed Apr 12 16:42:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 82571 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp470663vqo; Wed, 12 Apr 2023 09:53:29 -0700 (PDT) X-Google-Smtp-Source: AKy350Y8lCWC1C9plrDOL8PijSiEe+5kNFMX1mpyo6LYs1aGKtXdLg13poJdHq73ZIN2LoN0U98S X-Received: by 2002:a05:6a20:4992:b0:db:f682:65ed with SMTP id fs18-20020a056a20499200b000dbf68265edmr3276561pzb.61.1681318409457; Wed, 12 Apr 2023 09:53:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681318409; cv=none; d=google.com; s=arc-20160816; b=ntO7M/EUIbjBfo9Q8TC0I85wqxXwLeSEhyOIrjHGEmdtPR/T1PRo4/AxbeQajHjM1x ix9CeET4p0T0HZrGAoHdUVG3F6GFASM7t2J9WWB6km/Qr7cmkOGzwj36lFXJ7YOv2TMX 26eaEsN1+7rprAQRieCbLT6dOL4dW77nKCBIpv6e5BbaBOF+3I3BPLS38iayNVcJJ7zb zxXsKba63AAx9QotqP8IZmZnPrY/Zr3PkNi3hTfeF4wK+QmavtFiqf5GmWVeeLANdV2d AtItMl/pK65sPuKxvDosQp2IVIwAun8TgS4yydKH4MZzt2o1M4KXma5Lpqfy8eaGhVfo H39g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AoupzZV60neLuDl2cXNTlifM0oGkfquzJdJQPjel9/o=; b=K/KpksswrF/WBfmmQ0uAA8cv86Mk829i2yf6sbvwJPx5dJDdULtymhZFSZacAELIuL /9/EnCGTz7X479EYBKFRVKhQBTHeunGpj/TAObM/UR2IbuNbrPv+ActpWn4iUFr9lqBr 7PivNClKaMjLtbPXoNqDpro+xu65gcSAjRkrP+bqsymbM7Kf2E3TFR2s9iDo7XPDsCHs v4xg+CocoJeSsUzpWJ8S29U51H1PYq0PDCuRHy0k7fphZIFr+1BuP6e8zPKTqzXfWwtw dOOdmecG0CGrsue4Q7vwt/b/L0wMump7241mV31/Va+IzgjPPSPnrB+A8lwBv93baUo3 YybA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hPB3rxrD; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v127-20020a626185000000b0063b1b437e53si1353223pfb.306.2023.04.12.09.53.14; Wed, 12 Apr 2023 09:53:29 -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=@redhat.com header.s=mimecast20190719 header.b=hPB3rxrD; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229749AbjDLQos (ORCPT + 99 others); Wed, 12 Apr 2023 12:44:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229567AbjDLQoN (ORCPT ); Wed, 12 Apr 2023 12:44:13 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08D0E448B for ; Wed, 12 Apr 2023 09:43:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317780; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AoupzZV60neLuDl2cXNTlifM0oGkfquzJdJQPjel9/o=; b=hPB3rxrD2dI1QPBys3g5wafqp8peA28f3RQV1wIwEPoxfT2LYZraDjLdQirxtEVstV226L 6LgRuOOoxf8CDyjIqL7UWxfzNWNVGM816oEd6SJgqmX+Dt9rCgWhGvsCdpWJi5hN7tFe4o BL/DqCUDaUeRHmj0cE3+UgWLGKBeqnM= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-114-_MJ8t0T7Oaics3B9w-nD4A-1; Wed, 12 Apr 2023 12:42:59 -0400 X-MC-Unique: _MJ8t0T7Oaics3B9w-nD4A-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-74a90355636so62117185a.0 for ; Wed, 12 Apr 2023 09:42:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317777; x=1683909777; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AoupzZV60neLuDl2cXNTlifM0oGkfquzJdJQPjel9/o=; b=PdGLWHsG6HRHsWyjdi+mkv7h9BL4PyUceSYtX8gi8c8YwgIauDPeW0jYslFmYTLJNV rB25KwqEfBd73IFIUyTJ6P32AgIHQK4jy1AjPC8gn6XS9NnZ1SzW20l+MIF6XegOXosU 4rXgZ3Cqyl+UKgLDh+KAKkq4HA6Gs84Wv80TEjHpEQ0I4+tAwPBX1lwtvy0as3c5GSr6 2lKxlhcp0RjX3MAOA7Nv9Y1dRsEYgyOMo91sWYVwRkSJuV1SyduWSBp9/P0gWOHmq/pt pvzYw7ZqR1U/2Wq4bPruL5zza0dzUc4UZiCA2qODqNgEGEpahjD68FAQUHw9+BjvpNgP NyAQ== X-Gm-Message-State: AAQBX9d0VvMIDlYg0rMJi/Z8hbWZiD2xdhL1wuxhu9IMRMIvOSL5FuSI pMhVU7zG1R1ruwT8IBkKLWnv3MjFnVEAVbav0EMjcxCrQe+1UT5QfWMPyEuYLdvMR7J8BGweuef 9wlQw/2/FNcSKDDg6TF1QJJRK2NCjgPe6Ht8fJugOSdad2eU7uXx1djbPorendZ7PMi0JXU6fmo VhREg54w== X-Received: by 2002:a05:6214:5290:b0:5ed:c96e:ca4a with SMTP id kj16-20020a056214529000b005edc96eca4amr14523324qvb.1.1681317777552; Wed, 12 Apr 2023 09:42:57 -0700 (PDT) X-Received: by 2002:a05:6214:5290:b0:5ed:c96e:ca4a with SMTP id kj16-20020a056214529000b005edc96eca4amr14523277qvb.1.1681317777138; Wed, 12 Apr 2023 09:42:57 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id o24-20020a05620a229800b00747d211536dsm4766694qkh.107.2023.04.12.09.42.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:42:56 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Andrea Arcangeli , Mike Kravetz , Nadav Amit , David Hildenbrand , Mike Rapoport , Axel Rasmussen , Leonardo Bras Soares Passos , peterx@redhat.com, Mike Rapoport Subject: [PATCH v2 15/31] selftests/mm: uffd_open_{dev|sys}() Date: Wed, 12 Apr 2023 12:42:54 -0400 Message-Id: <20230412164254.328335-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-1-peterx@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762990132604259864?= X-GMAIL-MSGID: =?utf-8?q?1762990132604259864?= Provide two helpers to open an uffd handle. Drop the error checks around SKIPs because it's inside an errexit() anyway, which IMHO doesn't really help much if the test will not continue. Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Peter Xu Reviewed-by: Axel Rasmussen --- tools/testing/selftests/mm/uffd-common.c | 28 +++++------------------- tools/testing/selftests/mm/vm_util.c | 24 ++++++++++++++++++++ tools/testing/selftests/mm/vm_util.h | 2 ++ 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index daa5b5781e7a..09ea24c5f02c 100644 --- a/tools/testing/selftests/mm/uffd-common.c +++ b/tools/testing/selftests/mm/uffd-common.c @@ -192,34 +192,16 @@ void uffd_stats_report(struct uffd_stats *stats, int n_cpus) printf("\n"); } -static int __userfaultfd_open_dev(void) -{ - int fd, _uffd; - - fd = open("/dev/userfaultfd", O_RDWR | O_CLOEXEC); - if (fd < 0) - errexit(KSFT_SKIP, "opening /dev/userfaultfd failed"); - - _uffd = ioctl(fd, USERFAULTFD_IOC_NEW, UFFD_FLAGS); - if (_uffd < 0) - errexit(errno == ENOTTY ? KSFT_SKIP : 1, - "creating userfaultfd failed"); - close(fd); - return _uffd; -} - void userfaultfd_open(uint64_t *features) { struct uffdio_api uffdio_api; if (test_dev_userfaultfd) - uffd = __userfaultfd_open_dev(); - else { - uffd = syscall(__NR_userfaultfd, UFFD_FLAGS); - if (uffd < 0) - errexit(errno == ENOSYS ? KSFT_SKIP : 1, - "creating userfaultfd failed"); - } + uffd = uffd_open_dev(UFFD_FLAGS); + else + uffd = uffd_open_sys(UFFD_FLAGS); + if (uffd < 0) + err("uffd open failed (dev=%d)", test_dev_userfaultfd); uffd_flags = fcntl(uffd, F_GETFD, NULL); uffdio_api.api = UFFD_API; diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index bb633d050d71..5ee6c4688a7c 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include "../kselftest.h" #include "vm_util.h" @@ -230,3 +232,25 @@ int uffd_unregister(int uffd, void *addr, uint64_t len) return ret; } + +int uffd_open_dev(unsigned int flags) +{ + int fd, uffd; + + fd = open("/dev/userfaultfd", O_RDWR | O_CLOEXEC); + if (fd < 0) + return fd; + uffd = ioctl(fd, USERFAULTFD_IOC_NEW, flags); + close(fd); + + return uffd; +} + +int uffd_open_sys(unsigned int flags) +{ +#ifdef __NR_userfaultfd + return syscall(__NR_userfaultfd, flags); +#else + return -1; +#endif +} diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h index 3a9762022efd..481354141533 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -48,6 +48,8 @@ unsigned long default_huge_page_size(void); int uffd_register(int uffd, void *addr, uint64_t len, bool miss, bool wp, bool minor); int uffd_unregister(int uffd, void *addr, uint64_t len); +int uffd_open_dev(unsigned int flags); +int uffd_open_sys(unsigned int flags); /* * On ppc64 this will only work with radix 2M hugepage size