From patchwork Thu Jan 5 10:18:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 39470 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp233423wrt; Thu, 5 Jan 2023 02:39:08 -0800 (PST) X-Google-Smtp-Source: AMrXdXusygrX2CfiV/DJgSGO7AaHtZwLleXoPvd6AMfkdNbrXNs/xMZMjrLKRtDwLdMUZ/1WL4hd X-Received: by 2002:a05:6a21:32a5:b0:a4:93ca:a2d with SMTP id yt37-20020a056a2132a500b000a493ca0a2dmr91067511pzb.49.1672915147940; Thu, 05 Jan 2023 02:39:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672915147; cv=none; d=google.com; s=arc-20160816; b=CMazfiMEzoucb8t5G/3kVg2qOpI8tcrh+UX1/dv/OIg+jn40Q0XSfHdkJnRQan0qF9 j7uF4CBfHzGsubDt4O4xrkkyIDRFNBqB7PrdhQAk6R23wRw9GkNATvijtPNt933ZRu2V xzl2OffZ84RbSLmsARlLJX1qIK+JwiIOa7ykYX8KX8sV36gXiQmo8B/DmZZ2VpPJgESe yKX//z15rSbV0ht+PPrgBLJsBBd6e0+fhNM2wVuWLmgWi1uQ2+brN+iGHncynVk1TGJ8 57b2/hUPzZnGycY+nRMY9ZPC3ggMrtUTttx5Clxm5F0RpCdOf6n87e2Je7TR83EJjYAU qGMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=EgIq+1+XdJ7ES1jkz4HOORu1ptYeWb67NT6vWcXFv0I=; b=c5bXFC4Ejw3deB4/Udvdon+p2gAzTlmECuPXSC164DNiWBoUvCBRUvVjkZIl0KyJnM wpXLni8rpDHYlLA6n+BWlOS9hKYNvtF2cOFjVoxM72DxO2sn81Tw69BhOi3qQSUc0I2c ANbqDb3r3nhIda62GtOLag0cPvHwV5Q9koNvtfKIlA3ypCszcrxy3j+xy3iaEKaQ7Scy wM+v6xMeGuM9R3FmYZi59EMUpngCItjYyBBHldTk41jGoD+CBqe5BaJdFh5FdiNNrRhE bVephEDvEHIDhwmbN5CttIbnHs1xvThjZzC3Gdvh4Oyi9raMQdVLVKgcZPanDpCinuCC 9F2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=c7YTwst+; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z4-20020a170902ccc400b00192aecb230dsi15837591ple.209.2023.01.05.02.38.54; Thu, 05 Jan 2023 02:39:07 -0800 (PST) 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=@google.com header.s=20210112 header.b=c7YTwst+; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233276AbjAEKXb (ORCPT + 99 others); Thu, 5 Jan 2023 05:23:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233071AbjAEKVy (ORCPT ); Thu, 5 Jan 2023 05:21:54 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 306D24FD63 for ; Thu, 5 Jan 2023 02:19:57 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id a4-20020a5b0004000000b006fdc6aaec4fso36883924ybp.20 for ; Thu, 05 Jan 2023 02:19:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=EgIq+1+XdJ7ES1jkz4HOORu1ptYeWb67NT6vWcXFv0I=; b=c7YTwst+CXQAde/EC4BKjPkQxQslDinc3BRCYCIN4Tt+2cEbTnwk0TU3bwgaP6mee9 kEFf2wTCzpL5xUl7MHVCSLefee0s5iUkXnq/BXDX7FnSsqYa/Xt+MvBh9hZyl95WL9rl VzfwsERIDQ64g0aldVR7KIXBbKA6yB7hRzB4DLlyHtDcrEcwlH1V2Z30dYIICNHagJAF qbjJhxKV7+3WFweiPZZyzSyK5XDS2kSEUb5iNNMFi6ZL9VpJlG160jKr5BCMmceiKdCo 7Po0f1f/HHNFQPSs5wgIOpRg/gJwmw4aukeHNgtzIRiDRL7lBaiZl3zRpKSymn7/ugDK YcAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=EgIq+1+XdJ7ES1jkz4HOORu1ptYeWb67NT6vWcXFv0I=; b=GW19mtECeLCwwUkMK2+PLwq2ZwvlpNPRflD2FnrPsm9+Egg3ZSV67OAaLYTbSn3SXD tzqDjzf4OuhMT8i2yRfCKZkA09p8DvQJM9r8HdF6XHSHbxYUNTS1GnMij9Tf6ATjzHHi 2p4AaFSJPr4RHqUsy19wWcJoqrTOKt9+NvL8ru/6vS6C2Mq6ug6aPX1QsOp9z/o3hCC9 y85M592N3pKZMg5Zmvz6YruzTvILIj0EaeXQCeR1lY4LA8AVHaDYMm0pHLwSSkkgYLw6 QjmPNNjrZo0tLKhQ2mjNhXNCnNJrqHRTsMb6rI06VxmkLcjrhT3wABOSqrt/LJ4yHcj4 GPBQ== X-Gm-Message-State: AFqh2krdFVnCwezt++MtpQ6ypsGHsydYTzxIM3AD6BUZHarzr1veO7q2 XL1Nw4TijIdQi4feGBqbeedWVpFp9ShDZoYY X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a81:17d6:0:b0:3ea:9ce2:cd76 with SMTP id 205-20020a8117d6000000b003ea9ce2cd76mr93735ywx.217.1672913996509; Thu, 05 Jan 2023 02:19:56 -0800 (PST) Date: Thu, 5 Jan 2023 10:18:41 +0000 In-Reply-To: <20230105101844.1893104-1-jthoughton@google.com> Mime-Version: 1.0 References: <20230105101844.1893104-1-jthoughton@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230105101844.1893104-44-jthoughton@google.com> Subject: [PATCH 43/46] selftests/kvm: add HugeTLB HGM to KVM demand paging selftest From: James Houghton To: Mike Kravetz , Muchun Song , Peter Xu Cc: David Hildenbrand , David Rientjes , Axel Rasmussen , Mina Almasry , "Zach O'Keefe" , Manish Mishra , Naoya Horiguchi , "Dr . David Alan Gilbert" , "Matthew Wilcox (Oracle)" , Vlastimil Babka , Baolin Wang , Miaohe Lin , Yang Shi , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, James Houghton X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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?1754178674417947944?= X-GMAIL-MSGID: =?utf-8?q?1754178674417947944?= This test exercises the GUP paths for HGM. MADV_COLLAPSE is not tested. Signed-off-by: James Houghton --- tools/testing/selftests/kvm/demand_paging_test.c | 2 +- tools/testing/selftests/kvm/include/test_util.h | 2 ++ .../selftests/kvm/include/userfaultfd_util.h | 6 +++--- tools/testing/selftests/kvm/lib/kvm_util.c | 2 +- tools/testing/selftests/kvm/lib/test_util.c | 14 ++++++++++++++ tools/testing/selftests/kvm/lib/userfaultfd_util.c | 14 +++++++++++--- 6 files changed, 32 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c index b0e1fc4de9e2..e534f9c927bf 100644 --- a/tools/testing/selftests/kvm/demand_paging_test.c +++ b/tools/testing/selftests/kvm/demand_paging_test.c @@ -170,7 +170,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) uffd_descs[i] = uffd_setup_demand_paging( p->uffd_mode, p->uffd_delay, vcpu_hva, vcpu_args->pages * memstress_args.guest_page_size, - &handle_uffd_page_request); + p->src_type, &handle_uffd_page_request); } } diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h index 80d6416f3012..a2106c19a614 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -103,6 +103,7 @@ enum vm_mem_backing_src_type { VM_MEM_SRC_ANONYMOUS_HUGETLB_16GB, VM_MEM_SRC_SHMEM, VM_MEM_SRC_SHARED_HUGETLB, + VM_MEM_SRC_SHARED_HUGETLB_HGM, NUM_SRC_TYPES, }; @@ -121,6 +122,7 @@ size_t get_def_hugetlb_pagesz(void); const struct vm_mem_backing_src_alias *vm_mem_backing_src_alias(uint32_t i); size_t get_backing_src_pagesz(uint32_t i); bool is_backing_src_hugetlb(uint32_t i); +bool is_backing_src_shared_hugetlb(enum vm_mem_backing_src_type src_type); void backing_src_help(const char *flag); enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name); long get_run_delay(void); diff --git a/tools/testing/selftests/kvm/include/userfaultfd_util.h b/tools/testing/selftests/kvm/include/userfaultfd_util.h index 877449c34592..d91528a58245 100644 --- a/tools/testing/selftests/kvm/include/userfaultfd_util.h +++ b/tools/testing/selftests/kvm/include/userfaultfd_util.h @@ -26,9 +26,9 @@ struct uffd_desc { pthread_t thread; }; -struct uffd_desc *uffd_setup_demand_paging(int uffd_mode, useconds_t delay, - void *hva, uint64_t len, - uffd_handler_t handler); +struct uffd_desc *uffd_setup_demand_paging( + int uffd_mode, useconds_t delay, void *hva, uint64_t len, + enum vm_mem_backing_src_type src_type, uffd_handler_t handler); void uffd_stop_demand_paging(struct uffd_desc *uffd); diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index c88c3ace16d2..67e7223f054b 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -972,7 +972,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, region->fd = -1; if (backing_src_is_shared(src_type)) region->fd = kvm_memfd_alloc(region->mmap_size, - src_type == VM_MEM_SRC_SHARED_HUGETLB); + is_backing_src_shared_hugetlb(src_type)); region->mmap_start = mmap(NULL, region->mmap_size, PROT_READ | PROT_WRITE, diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c index 5c22fa4c2825..712a0878932e 100644 --- a/tools/testing/selftests/kvm/lib/test_util.c +++ b/tools/testing/selftests/kvm/lib/test_util.c @@ -271,6 +271,13 @@ const struct vm_mem_backing_src_alias *vm_mem_backing_src_alias(uint32_t i) */ .flag = MAP_SHARED, }, + [VM_MEM_SRC_SHARED_HUGETLB_HGM] = { + /* + * Identical to shared_hugetlb except for the name. + */ + .name = "shared_hugetlb_hgm", + .flag = MAP_SHARED, + }, }; _Static_assert(ARRAY_SIZE(aliases) == NUM_SRC_TYPES, "Missing new backing src types?"); @@ -289,6 +296,7 @@ size_t get_backing_src_pagesz(uint32_t i) switch (i) { case VM_MEM_SRC_ANONYMOUS: case VM_MEM_SRC_SHMEM: + case VM_MEM_SRC_SHARED_HUGETLB_HGM: return getpagesize(); case VM_MEM_SRC_ANONYMOUS_THP: return get_trans_hugepagesz(); @@ -305,6 +313,12 @@ bool is_backing_src_hugetlb(uint32_t i) return !!(vm_mem_backing_src_alias(i)->flag & MAP_HUGETLB); } +bool is_backing_src_shared_hugetlb(enum vm_mem_backing_src_type src_type) +{ + return src_type == VM_MEM_SRC_SHARED_HUGETLB || + src_type == VM_MEM_SRC_SHARED_HUGETLB_HGM; +} + static void print_available_backing_src_types(const char *prefix) { int i; diff --git a/tools/testing/selftests/kvm/lib/userfaultfd_util.c b/tools/testing/selftests/kvm/lib/userfaultfd_util.c index 92cef20902f1..3c7178d6c4f4 100644 --- a/tools/testing/selftests/kvm/lib/userfaultfd_util.c +++ b/tools/testing/selftests/kvm/lib/userfaultfd_util.c @@ -25,6 +25,10 @@ #ifdef __NR_userfaultfd +#ifndef MADV_SPLIT +#define MADV_SPLIT 26 +#endif + static void *uffd_handler_thread_fn(void *arg) { struct uffd_desc *uffd_desc = (struct uffd_desc *)arg; @@ -108,9 +112,9 @@ static void *uffd_handler_thread_fn(void *arg) return NULL; } -struct uffd_desc *uffd_setup_demand_paging(int uffd_mode, useconds_t delay, - void *hva, uint64_t len, - uffd_handler_t handler) +struct uffd_desc *uffd_setup_demand_paging( + int uffd_mode, useconds_t delay, void *hva, uint64_t len, + enum vm_mem_backing_src_type src_type, uffd_handler_t handler) { struct uffd_desc *uffd_desc; bool is_minor = (uffd_mode == UFFDIO_REGISTER_MODE_MINOR); @@ -140,6 +144,10 @@ struct uffd_desc *uffd_setup_demand_paging(int uffd_mode, useconds_t delay, "ioctl UFFDIO_API failed: %" PRIu64, (uint64_t)uffdio_api.api); + if (src_type == VM_MEM_SRC_SHARED_HUGETLB_HGM) + TEST_ASSERT(!madvise(hva, len, MADV_SPLIT), + "Could not enable HGM"); + uffdio_register.range.start = (uint64_t)hva; uffdio_register.range.len = len; uffdio_register.mode = uffd_mode;