From patchwork Mon Jul 18 11:47:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 12921636 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 E0EA5CCA479 for ; Mon, 18 Jul 2022 19:22:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F1F4F6B0078; Mon, 18 Jul 2022 15:22:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EAC8A6B007B; Mon, 18 Jul 2022 15:22:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7C2D6B007D; Mon, 18 Jul 2022 15:22:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A4B1B6B0078 for ; Mon, 18 Jul 2022 15:22:44 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6462860420 for ; Mon, 18 Jul 2022 19:22:44 +0000 (UTC) X-FDA: 79701192648.14.C42ADB2 Received: from relay3.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by imf06.hostedemail.com (Postfix) with ESMTP id D341E180055 for ; Mon, 18 Jul 2022 19:22:43 +0000 (UTC) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 82AC2207C8 for ; Mon, 18 Jul 2022 19:22:43 +0000 (UTC) X-FDA: 79701192606.10.AB6777C Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf13.hostedemail.com (Postfix) with ESMTP id CAF2C20098 for ; Mon, 18 Jul 2022 19:22:42 +0000 (UTC) Received: by mail-pl1-f181.google.com with SMTP id q5so9931086plr.11 for ; Mon, 18 Jul 2022 12:22:42 -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=ZC1di4K8mzuPHZwILjb2huyZD4/t1Q7mzfb990p6oBE=; b=KfM1I1BxerLWQVZE4Moy1hZM2GQJiZcjE8z5MiLmlxMI1jPpMeJrbjeyD17XUuCxwo Fk/ck4Ryq7hPsC0zIvoSTVPdRnCHG6H8gxGolKpW2ohoBiizYSpWSyvPno8/TxA88d8r ox9bcTZyH7dIjyY5sS2ysMigSrHn5OjAybtTQkk9DxrQlLOj9Euarksisyyqd3fWr6hS MtNvde6VmAFZ8/tn4deZBtDY2DNL4U76krQupaP1/MYnIkCIqx5D5FMs0BcyIYu4ER8d FXKbFFTSTOg+/dWnWUW/PllHGg/EZhNt8pPopr4amyxBxUyYQlc8Se4gE8yrQcBqYUYj 05nw== 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=ZC1di4K8mzuPHZwILjb2huyZD4/t1Q7mzfb990p6oBE=; b=vK3c/dWOi0xZ5qnjiGM3Ms7MUmU8e0x4rI2Du9WKzT9kQ84jH9jntWEUzFIHOljYRM 15KwzrC33tWYgHi5LStVqHdUB8aHDNORKd7MLkSqE57ucuSTOYZCDHZtXYMBK2Jqtj8A Ld7wAMJtz8G+iyEGxuxUJEeg2Rjeoi6QsY83Z4/hCoMhufXlbX4RrR5px28lcaJDxPLH Md/90XkdrvkrPFsPe5CMVWPOTuhtdsdC+1qKJ/lY2ydC8b2F+4dauGDPRCsGh9f5lRxD /VLhxrIxslK5P48Z46UWDyB9M5atUwwT5nctRw9eMq97OX61KKPDHtw6ReFWkvU6JVOE cNJA== X-Gm-Message-State: AJIora//KU8EdMNnq3smO6/Susy8KQcdfYWN6EGnF22e1rIooAOqLk++ 2D/ljVrjALnu5inrMRKRQc0Z3IdXJLc= X-Google-Smtp-Source: AGRyM1sUl8K4UViYcikdUSgOopTNYKHV3R6AKur+LcYXEMosP5XAcxxOGZIfACeP8Bz7avwE/QnDnw== X-Received: by 2002:a17:90a:7ac4:b0:1ef:a606:4974 with SMTP id b4-20020a17090a7ac400b001efa6064974mr40815100pjl.51.1658172161757; Mon, 18 Jul 2022 12:22:41 -0700 (PDT) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id g9-20020a625209000000b0051bc5f4df1csm9613570pfb.154.2022.07.18.12.22.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 12:22:41 -0700 (PDT) From: Nadav Amit X-Google-Original-From: Nadav Amit To: linux-mm@kvack.org Cc: Andrew Morton , Nadav Amit , Mike Kravetz , Hugh Dickins , Axel Rasmussen , Peter Xu , David Hildenbrand , Mike Rapoport Subject: [PATCH v2 5/5] selftest/userfaultfd: test read/write hints Date: Mon, 18 Jul 2022 04:47:48 -0700 Message-Id: <20220718114748.2623-6-namit@vmware.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220718114748.2623-1-namit@vmware.com> References: <20220718114748.2623-1-namit@vmware.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658172163; 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=ZC1di4K8mzuPHZwILjb2huyZD4/t1Q7mzfb990p6oBE=; b=0s6TJZ2bfzAiXxacw6reNOqgsFsBn0sKN7CgLToqP7R80OgR8f0Z7t7+RwWGEU6lBoMQ0d DSR/ei5+5iyzsg6jMqpmNy8o3Vjk0qbwKyfjLGv62iSI1PcHmO0lNjaQ4ZZnCBBeqSk8m9 grxgeUezd4MEl0lD0mcPcdz6MuTfnKw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658172163; a=rsa-sha256; cv=none; b=6wFsKEHKO2/13DFXDLm89RZlo0dSEx+7Vptbzm/FLFfr5DqQtTS6/zl916B2yJhCsziU2N +ffRmD4v8GnQfEw/fPjxfblgRVWXqgwokta42Viq4K/4gqpSns0+iP+cjrvOQO0Wq5WIVk IKUgtSh8LviAENTNjomkcHSSUpDuegE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=KfM1I1Bx; dmarc=pass (policy=none) header.from=gmail.com; spf=none (imf06.hostedemail.com: domain of MAILER-DAEMON@hostedemail.com has no SPF policy when checking 216.40.44.10) smtp.mailfrom=MAILER-DAEMON@hostedemail.com X-Rspamd-Server: rspam10 X-Stat-Signature: h1c99q73imuwghxfusmikofokz1kna9d X-Rspam-User: X-Rspamd-Queue-Id: D341E180055 X-HE-Tag-Orig: 1658172162-899486 Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=KfM1I1Bx; dmarc=pass (policy=none) header.from=gmail.com; spf=none (imf06.hostedemail.com: domain of MAILER-DAEMON@hostedemail.com has no SPF policy when checking 216.40.44.10) smtp.mailfrom=MAILER-DAEMON@hostedemail.com X-HE-Tag: 1658172163-36205 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 | 16 ++++--- tools/testing/selftests/vm/userfaultfd.c | 54 +++++++++++++++++++++-- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/vm/run_vmtests.sh b/tools/testing/selftests/vm/run_vmtests.sh index 27c01c35c7a9..296862547ff9 100755 --- a/tools/testing/selftests/vm/run_vmtests.sh +++ b/tools/testing/selftests/vm/run_vmtests.sh @@ -120,11 +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 -# Test requires source and destination huge pages. Size of source -# (half_ufd_size_MB) is passed as argument to test. -run_test ./userfaultfd hugetlb "$half_ufd_size_MB" 32 -run_test ./userfaultfd shmem 20 16 +uffd_mods=("" ":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 7c3f1b0ab468..d54f65246bd8 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -85,6 +85,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; @@ -518,6 +520,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); } @@ -531,6 +539,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); @@ -621,6 +635,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 */ @@ -1048,6 +1069,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) { @@ -1584,8 +1612,6 @@ unsigned long default_huge_page_size(void) static void set_test_type(const char *type) { - uint64_t features = UFFD_API_FEATURES; - if (!strcmp(type, "anon")) { test_type = TEST_ANON; uffd_test_ops = &anon_uffd_test_ops; @@ -1606,6 +1632,28 @@ static void set_test_type(const char *type) } else { err("Unknown test type: %s", type); } +} + +static void parse_test_type_arg(const char *raw_type) +{ + char *buf = strdup(raw_type); + uint64_t features = UFFD_API_FEATURES; + + while (buf) { + const char *token = strsep(&buf, ":"); + + if (!test_type) + set_test_type(token); + 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); + } + + if (!test_type) + err("failed to parse test type argument: '%s'", raw_type); if (test_type == TEST_HUGETLB) page_size = default_huge_page_size(); @@ -1653,7 +1701,7 @@ int main(int argc, char **argv) err("failed to arm SIGALRM"); alarm(ALARM_INTERVAL_SECS); - set_test_type(argv[1]); + parse_test_type_arg(argv[1]); nr_cpus = sysconf(_SC_NPROCESSORS_ONLN); nr_pages_per_cpu = atol(argv[2]) * 1024*1024 / page_size /