From patchwork Thu Mar 30 16:07:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13194497 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 A2090C77B62 for ; Thu, 30 Mar 2023 16:07:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 40A986B0098; Thu, 30 Mar 2023 12:07:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BA7D6B0099; Thu, 30 Mar 2023 12:07:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 25BAE900002; Thu, 30 Mar 2023 12:07:58 -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 1275F6B0098 for ; Thu, 30 Mar 2023 12:07:58 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8DEF7120AA1 for ; Thu, 30 Mar 2023 16:07:57 +0000 (UTC) X-FDA: 80626045794.19.F25CDBD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 34D51A0031 for ; Thu, 30 Mar 2023 16:07:55 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LLhrok7D; spf=pass (imf15.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680192475; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=y+QAWrtqijcBRWNbbJvqOTcdIrT0hJlkJlw2bNALieY=; b=ppW6ExqDv3QUkF+hFQBLd97WBSmBN/ugFz8vyI6fhTAlpD3A5YI8LYkP2/T27MKJq2KRgJ mYliENzzD7bWJf2YpZ9ee/ZPcW8fUEdpCe7SWZf8EjLKjPNTYx4BH38Q+pfjzugUesftBv 65G8uFcQ+u3bfa74mcIEgm6gKSYbeqk= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LLhrok7D; spf=pass (imf15.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192475; a=rsa-sha256; cv=none; b=nFWYtO4Aynvv6dQvMcvplPeOpTvYqavp+v6Z7Ke0pXTeoYgIKEF67L8MlESk5MBzPiWPTO CUEZXis2GqPcnwe2DJhF9eHbZE0jL0dtT3miZfZbsE37BRe6Auc21OPnwffhvBKjo6Y6/i c3fHfG1mySIbifUT0Z5tkSgo5rkGslk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192474; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y+QAWrtqijcBRWNbbJvqOTcdIrT0hJlkJlw2bNALieY=; b=LLhrok7DfJR0AomX8qvUMJxVfniyIfmG4v+yvKZDuBy6FczHqJYZQ8TkQqPbsc8K7G4TES evXH4wCAsh5YLvhtSHJdV95+myA9jsQCLQnxbaxLWP1lx4/01RI2dApdt1scDncEByX/1/ pqy8SmUsGjy0Dk97nb+xnMSNFrvEikA= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-59-5jjfm70vO8aYH0CdLP3NIg-1; Thu, 30 Mar 2023 12:07:53 -0400 X-MC-Unique: 5jjfm70vO8aYH0CdLP3NIg-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-57c67ea348eso12977346d6.1 for ; Thu, 30 Mar 2023 09:07:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192472; 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=y+QAWrtqijcBRWNbbJvqOTcdIrT0hJlkJlw2bNALieY=; b=WX4xr8R0AnQI4HjxUtWa4+r01Ub4fbw9vO5m1pMurf5B/EffW/SLJYpT4w0UosMXgv TaFxNs+xZmBNVDq05oV37ZifDlPQhcx/03tOgkvWIBfdm4f77w1mcYRc0jHYR0o8Y3NL HTf3cS6yMW28j+oH1Jmz2GIAeMwkFV/LAb6PWM8RZvJ491UTC22l24K4cNcH+Ji10zv2 Tki2AepN9BSCuqjWOZI3xhf3Fz7Us+EgU96Ii/Cx9Y8nNBVPvopyJybShK074+X4EV59 aYLaZ1hs/4Z2tze+8r6ViZvbmIeo0f9250uxboteFz0LY0KIPt4Wt5nN249GRIz9chde ifSA== X-Gm-Message-State: AAQBX9fFyJFC/yS/dWT9ieDriIE7LaubN+mK3e894qLCib290DBDzVEQ 8TT9x5D7wjH5FcIB6phJ93sMWHSnJIAlGTyN0L/uW9LotoMQjwhWKdqXSkYZshWhU3AdLg3Nd7e ztNnttrFjP2jjXnapiRCfLsLmYcosZ+SsLfJOlABnKJ86wrWXMG8WsjoBYscw62cbgZC2 X-Received: by 2002:a05:6214:5089:b0:57d:747b:1f7 with SMTP id kk9-20020a056214508900b0057d747b01f7mr3712141qvb.1.1680192472277; Thu, 30 Mar 2023 09:07:52 -0700 (PDT) X-Google-Smtp-Source: AKy350ZAVMXrazBe1vAQ/esRv12K7m2amBl/weU4s0XRJNLyUQvvVZevPT3MnJh9bSHpN/NtrYQMVw== X-Received: by 2002:a05:6214:5089:b0:57d:747b:1f7 with SMTP id kk9-20020a056214508900b0057d747b01f7mr3712094qvb.1.1680192471894; Thu, 30 Mar 2023 09:07:51 -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 ev11-20020a0562140a8b00b005dd8b9345bcsm5580475qvb.84.2023.03.30.09.07.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:07:51 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrea Arcangeli , peterx@redhat.com, David Hildenbrand , Andrew Morton , Nadav Amit , Mike Kravetz , Axel Rasmussen , Leonardo Bras Soares Passos , Mike Rapoport Subject: [PATCH 15/29] selftests/mm: uffd_open_{dev|sys}() Date: Thu, 30 Mar 2023 12:07:49 -0400 Message-Id: <20230330160749.3107270-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 34D51A0031 X-Stat-Signature: eibjry8zigmqf4xi6xawfkcygikb4615 X-HE-Tag: 1680192475-935324 X-HE-Meta: U2FsdGVkX19IrqSaZCpp4FIs9MNJ7Xr58eLYPHW6Lvj8/YDNXo/9SkRP5132z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TbUfR3TnzMUzQeVgvd/yuLY/Lye2H7uoHc0mqjT1Q80lCAyxBWFkEDDlHrvFolAWhAu4Kd3YL3oiKNP7jAbgURweeAKhy37wMLBNDzr1zdYTlf9JjpxMdSDSjwxB/2b2LiE+XRPqmfA989HkwNKLT1Cy7RWLzmDOKF4NDFng2FWOaAMFIRkEzhltQYQoWMvbXpdLXdlQGH6Izeh8g5D7U7Pz9LuT2gOZqyLyXqK3HP/Myj9S/8hUy335PIjwMxsNI83MSAXFSw7WofiuRj54EmvFxE7u1TH9AIRMuDF4P/HJpTyLgewFT6OTzRJ0uy9yWmyBbtJ3qKCxbsWKRpmXf2M+wKrkIQah/wEIjHx6UVwQM= 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: 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. Signed-off-by: Peter Xu Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) --- tools/testing/selftests/mm/uffd-common.c | 28 +++++------------------- tools/testing/selftests/mm/vm_util.c | 24 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-common.c b/tools/testing/selftests/mm/uffd-common.c index 17f2bb82c3db..3a9b5c1aca9d 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 10e76400ed70..7c2bf88d6393 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 +}