From patchwork Wed Jun 22 18:50:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 12891719 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 0A549C433EF for ; Thu, 23 Jun 2022 02:26:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6865E8E010E; Wed, 22 Jun 2022 22:25:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 637418E00FA; Wed, 22 Jun 2022 22:25:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B2DE8E010E; Wed, 22 Jun 2022 22:25:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 399B18E00FA for ; Wed, 22 Jun 2022 22:25:59 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 10D9635720 for ; Thu, 23 Jun 2022 02:25:59 +0000 (UTC) X-FDA: 79607910438.12.1E7F533 Received: from relay4.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by imf07.hostedemail.com (Postfix) with ESMTP id AC76340022 for ; Thu, 23 Jun 2022 02:25:58 +0000 (UTC) Received: from smtpin31.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 6601D61200 for ; Thu, 23 Jun 2022 02:25:58 +0000 (UTC) X-FDA: 79607910396.31.F109CB1 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by imf27.hostedemail.com (Postfix) with ESMTP id DBCE540015 for ; Thu, 23 Jun 2022 02:25:57 +0000 (UTC) Received: by mail-pj1-f49.google.com with SMTP id a11-20020a17090acb8b00b001eca0041455so2487780pju.1 for ; Wed, 22 Jun 2022 19:25:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NcPceKSRgtPTD9CpI6EICDoagd6x5gRxlN7y0kDN0bw=; b=ZTB1bY7/GK32DU08qg0ylip3r72EiobJb0xacUri4NAOupjuhG8c8M963oyoHIf9YB qsfcElNI6M/zieR11eAPCWYrVXajbANgV2PHunXI1qJdLCJMq1AlWU2UEkZSG96KWksq 9j9wwpHU9YpQTzGYmOOMLX266nsgOoLvGW6cWqBJPULFnxh5LM60ZC5PHr93GE4z1lkN UkzzpoS9q3RNK5gnoNJtZFO8qXF7EBd/DQLC/ROw1mDU1AV3so2tRNeKdZrUUQqXOKtJ W+PxbbevFsz7GFVSIKI1nHYKhPSFVDBz5ha45KL2A1CT1JQ+d/+FWssILyzXgz2IvzFN n60A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NcPceKSRgtPTD9CpI6EICDoagd6x5gRxlN7y0kDN0bw=; b=HZp8uEhhxA4aBMHwGsYLyMRFj1bWsIa99kclSc0SUDtRb9akk0sMwC0AltRIyq7L4X 5j8Gny5IwdEJ+3g1KgxIBkkRpzbNm5zzczlrk2POtq2liTyozmGIIhZh+D8ENgURsqEy rgYpd0tc9SNcPpxxIKR0R5wNM8teHkW7rkZ6rwgimoYTL69NvLy7aJaL1UNpCWXbyG97 r/t1b9YCH2XEiU+/JH0YZqcLS3Zk3Gzu66KolBqFrNIQoh1L4dTgA75XLDJTFN1vffog yrv+vk+MUcezhdCInilL9jWs5xOpSIs02Zo+T0sf6qOWicA1imO/QFOtcbDmK57Dn4IH 4WEw== X-Gm-Message-State: AJIora8pXPT4lfKKuSmLz6ZeRt5EXNC86louUEiKsL345jq1/vqvum+M L/UZsk2+JGjhIr9iiSPleErHap5tOSFONg== X-Google-Smtp-Source: AGRyM1s19uzxfg/bZxAY69ymTT8MiZLYUxhv0VmiQoALOW/sVd/QZVpw8dSCCAlBLVY8EfDm7e9egA== X-Received: by 2002:a17:903:22d0:b0:16a:3039:adc9 with SMTP id y16-20020a17090322d000b0016a3039adc9mr14291532plg.32.1655951156583; Wed, 22 Jun 2022 19:25:56 -0700 (PDT) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id ik10-20020a170902ab0a00b001617541c94fsm13423998plb.60.2022.06.22.19.25.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jun 2022 19:25:56 -0700 (PDT) From: Nadav Amit X-Google-Original-From: Nadav Amit To: linux-mm@kvack.org Cc: Nadav Amit , Mike Kravetz , Hugh Dickins , Andrew Morton , Axel Rasmussen , Peter Xu , David Hildenbrand , Mike Rapoport Subject: [PATCH v1 5/5] selftest/userfaultfd: test read/write hints Date: Wed, 22 Jun 2022 11:50:38 -0700 Message-Id: <20220622185038.71740-6-namit@vmware.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220622185038.71740-1-namit@vmware.com> References: <20220622185038.71740-1-namit@vmware.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655951158; a=rsa-sha256; cv=none; b=Znyw2syWzx4gwNeQQBlD1yTDpjbO41SvurPHelG4CRpoINoduzklgio+bkykG5gP5mspJO YITHRO/Ndh+XfIuOuARDBCFSnRHABVVaF4HTQRWO/yFx+NNEoMegeTvDmX8fe+//G8Hi7q z/Hi6jURYGb46TCLeJm8wMofqqtQvLo= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="ZTB1bY7/"; dmarc=pass (policy=none) header.from=gmail.com; spf=none (imf07.hostedemail.com: domain of MAILER-DAEMON@hostedemail.com has no SPF policy when checking 216.40.44.17) smtp.mailfrom=MAILER-DAEMON@hostedemail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655951158; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NcPceKSRgtPTD9CpI6EICDoagd6x5gRxlN7y0kDN0bw=; b=8kpE5sfeIk8b1OFV9Qjp79k7/vSAxPpEg0PNMttbs+qH9QJobTBsJJ1E9nmtRyjZ+V0DGL H4Hp7p0qOB+rlY1D6o3LvkDSt/NE3pISBKh8MKUxgbcYBGi5zxzexUl3M2v7017rcX8xHt fQ07KkpnYBuheAw9WQ2a9Q8+KQpJwkc= X-Rspamd-Queue-Id: AC76340022 X-HE-Tag-Orig: 1655951157-937872 X-Rspam-User: Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="ZTB1bY7/"; dmarc=pass (policy=none) header.from=gmail.com; spf=none (imf07.hostedemail.com: domain of MAILER-DAEMON@hostedemail.com has no SPF policy when checking 216.40.44.17) smtp.mailfrom=MAILER-DAEMON@hostedemail.com X-Rspamd-Server: rspam03 X-Stat-Signature: e9c4jy9opaod8f7k6hoz3fc7rx57k83p X-HE-Tag: 1655951158-248695 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: From: Nadav Amit Test UFFDIO_*_MODE_ACCESS_LIKELY and UFFDIO_*_MODE_WRITE_LIKELY. Introduce a modifier to trigger the use of the hints. Add the test to run_vmtests.sh and add an array to run different userfaultfd configurations. Cc: Mike Kravetz Cc: Hugh Dickins Cc: Andrew Morton Cc: Axel Rasmussen Cc: Peter Xu Cc: David Hildenbrand Cc: Mike Rapoport Signed-off-by: Nadav Amit --- tools/testing/selftests/vm/run_vmtests.sh | 23 ++++++++-------- tools/testing/selftests/vm/userfaultfd.c | 32 +++++++++++++++++++++++ 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/vm/run_vmtests.sh b/tools/testing/selftests/vm/run_vmtests.sh index 930c54eb5b4b..b90e9cf9716d 100755 --- a/tools/testing/selftests/vm/run_vmtests.sh +++ b/tools/testing/selftests/vm/run_vmtests.sh @@ -120,18 +120,17 @@ run_test ./gup_test -a # Dump pages 0, 19, and 4096, using pin_user_pages: run_test ./gup_test -ct -F 0x1 0 19 0x1000 -run_test ./userfaultfd anon 20 16 -run_test ./userfaultfd anon:dev 20 16 -# Hugetlb tests require source and destination huge pages. Pass in half the -# size ($half_ufd_size_MB), which is used for *each*. -run_test ./userfaultfd hugetlb "$half_ufd_size_MB" 32 -run_test ./userfaultfd hugetlb:dev "$half_ufd_size_MB" 32 -run_test ./userfaultfd hugetlb_shared "$half_ufd_size_MB" 32 "$mnt"/uffd-test -rm -f "$mnt"/uffd-test -run_test ./userfaultfd hugetlb_shared:dev "$half_ufd_size_MB" 32 "$mnt"/uffd-test -rm -f "$mnt"/uffd-test -run_test ./userfaultfd shmem 20 16 -run_test ./userfaultfd shmem:dev 20 16 +uffd_mods=("" ":dev" ":access_likely" ":access_likely:write_likely" ":write_likely") + +for mod in "${uffd_mods[@]}"; do + run_test ./userfaultfd anon${mod} 20 16 + # Hugetlb tests require source and destination huge pages. Pass in half the + # size ($half_ufd_size_MB), which is used for *each*. + run_test ./userfaultfd hugetlb${mod} "$half_ufd_size_MB" 32 + run_test ./userfaultfd hugetlb_shared${mod} "$half_ufd_size_MB" 32 "$mnt"/uffd-test + rm -f "$mnt"/uffd-test + run_test ./userfaultfd shmem${mod} 20 16 +done #cleanup umount "$mnt" diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c index 28b881523d15..763458ce1d52 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -88,6 +88,8 @@ static volatile bool test_uffdio_zeropage_eexist = true; static bool test_uffdio_wp = true; /* Whether to test uffd minor faults */ static bool test_uffdio_minor = false; +static bool test_access_likely; +static bool test_write_likely; static bool map_shared; static int shm_fd; @@ -550,6 +552,12 @@ static void wp_range(int ufd, __u64 start, __u64 len, bool wp) /* Undo write-protect, do wakeup after that */ prms.mode = wp ? UFFDIO_WRITEPROTECT_MODE_WP : 0; + if (test_access_likely) + prms.mode |= UFFDIO_WRITEPROTECT_MODE_ACCESS_LIKELY; + + if (test_write_likely) + prms.mode |= UFFDIO_WRITEPROTECT_MODE_WRITE_LIKELY; + if (ioctl(ufd, UFFDIO_WRITEPROTECT, &prms)) err("clear WP failed: address=0x%"PRIx64, (uint64_t)start); } @@ -563,6 +571,12 @@ static void continue_range(int ufd, __u64 start, __u64 len) req.range.len = len; req.mode = 0; + if (test_access_likely) + req.mode |= UFFDIO_CONTINUE_MODE_ACCESS_LIKELY; + + if (test_write_likely) + req.mode |= UFFDIO_CONTINUE_MODE_WRITE_LIKELY; + if (ioctl(ufd, UFFDIO_CONTINUE, &req)) err("UFFDIO_CONTINUE failed for address 0x%" PRIx64, (uint64_t)start); @@ -653,6 +667,13 @@ static int __copy_page(int ufd, unsigned long offset, bool retry) uffdio_copy.mode = UFFDIO_COPY_MODE_WP; else uffdio_copy.mode = 0; + + if (test_access_likely) + uffdio_copy.mode |= UFFDIO_COPY_MODE_ACCESS_LIKELY; + + if (test_write_likely) + uffdio_copy.mode |= UFFDIO_COPY_MODE_WRITE_LIKELY; + uffdio_copy.copy = 0; if (ioctl(ufd, UFFDIO_COPY, &uffdio_copy)) { /* real retval in ufdio_copy.copy */ @@ -1080,6 +1101,13 @@ static int __uffdio_zeropage(int ufd, unsigned long offset, bool retry) uffdio_zeropage.range.start = (unsigned long) area_dst + offset; uffdio_zeropage.range.len = page_size; uffdio_zeropage.mode = 0; + + if (test_access_likely) + uffdio_zeropage.mode |= UFFDIO_ZEROPAGE_MODE_ACCESS_LIKELY; + + if (test_write_likely) + uffdio_zeropage.mode |= UFFDIO_ZEROPAGE_MODE_WRITE_LIKELY; + ret = ioctl(ufd, UFFDIO_ZEROPAGE, &uffdio_zeropage); res = uffdio_zeropage.zeropage; if (ret) { @@ -1648,6 +1676,10 @@ static void parse_test_type_arg(const char *raw_type) set_test_type(token); else if (!strcmp(token, "dev")) test_dev_userfaultfd = true; + else if (!strcmp(token, "access_likely")) + test_access_likely = true; + else if (!strcmp(token, "write_likely")) + test_write_likely = true; else err("unrecognized test mod '%s'", token); }