Received: by 2002:a05:6520:4211:b029:f4:110d:56bc with SMTP id o17csp1585850lkv; Wed, 19 May 2021 13:24:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCSopJOZU73d4JBwayR9IrewgikvmZ+8uWOCUjr1swsYmCOq0cdQOSFWHR8EHQ0Pd5Ii81 X-Received: by 2002:a5d:8b85:: with SMTP id p5mr1372309iol.43.1621455892349; Wed, 19 May 2021 13:24:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621455892; cv=none; d=google.com; s=arc-20160816; b=BnHAviktMTAjmoZ3np/QeBZWv3H4A5llMDW4MObIOpFiEdaYANRzx9jgpdFCIydXjt LnaYHOl6D1a/WH/LFx/KHdRLTwi8G32bvW5XMvx0G73aS+yA67kpT3Lt/tkxb/RYYGpw e9GIn+1dSjjUVJgd1CguJsZOWctG2LCeN61082D2AOdyAc0JXvT3MkdLNyQyHVUIK52i pDPxUBp7u3p4rjsOnb+MlXTNcVK+PJdXYYYocKaErywU6mgg/SZlgJEXLz1B/awb/kuL XTSD4XKt+EacjZCBqd9xWGWEkvE4f2mPLEGBa9EjQPvxodQIC1WD45VbXMUA4pRiD01Q T8yg== 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:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=xynO/3IOvrmFItcgXwqLWtJ7e/CIAjrQIN/NBcwC9/Y=; b=LxDYeUXcAfcrDIqTg53AKlbUH6wub4rJGVEfG8g2CdgYdBPS0cc3273t/KlgeIZVhU lIVL83N4S7/JALIG/617WYkeuxSS3ghhhjCU3UE2EKxS6RGNcAShG+O0bthYuY7MqHAC sPhIkx/RFKlvcEykShgppx9gTHDU4tuBm//K6omhhCr6q54GSh9W/lnA+E4gsG80XAyl DFpZmJizDKkJ7tYkv6q2CpiuUYJ9GR1CWt5OwqUk8m3BgmoBVU7R9BDYOAV5Ll5S8Y1F 9CjUTpibkbdY/7t45H6WTxwu167Az9t46fos/9DrdTgmlUtvnaDJV6P/TJPkaphlX44f thMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=E0kntoJR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w3si609764ilo.142.2021.05.19.13.24.39; Wed, 19 May 2021 13:24:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=E0kntoJR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S232949AbhESUGM (ORCPT + 99 others); Wed, 19 May 2021 16:06:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232849AbhESUFm (ORCPT ); Wed, 19 May 2021 16:05:42 -0400 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 57073C061346 for ; Wed, 19 May 2021 13:04:11 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id c9-20020a2580c90000b02904f86395a96dso19329408ybm.19 for ; Wed, 19 May 2021 13:04:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=xynO/3IOvrmFItcgXwqLWtJ7e/CIAjrQIN/NBcwC9/Y=; b=E0kntoJRKj0aslmfs+wcTw+D5xf7c/Q3qOFC/mgDQ8p97L0X9I38Aw5N4kwkRYLEYU UF/Z5lnoIBMGrXly4aMu7pWEMJC5h/BdCVhGysuZScH46byeMi24IUGASqghNkLT+YNG VLD+XPtz2kCG77Si2ohsP8HRw4Diy75AGv2GCnLyrtos9ffQ+6ydiCA7WpG9CPfwj2tM L2imdO5V6sB8i5B0R050+NZ7rBmHw7kWVLjrdfb/pYv/EkkU6i3Wz1kIc3G8BRi3OHZL aLfHTPiYNsDpj3d1LY/M5gg2YFgx9Pt5th72pp78s9+U3nRkGP+7gj7OeJoUnlKzijUx JGmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=xynO/3IOvrmFItcgXwqLWtJ7e/CIAjrQIN/NBcwC9/Y=; b=cnmEU3rGgFwdzJgkCLrbjSWgr/XGZFCUSKYfBlUMBPqBUh6TSGkLlamTgVc0J+EHTE 7uRaSWVzetAzCgHcTceVEs6r4EN5k7JSfvlw2v5oDJ0s0RiavfzdrSw2J0atze73yjCY b3X4xuTtBlgExPFq/BAH1eZ3BCN6uZnDta58xAel10TrRUjHAixEvel8w0J+anA45TE+ HnFEnHFHa26ncQ3aSRgzAqwupBCVOKLPn8E/bZHiZiYurdWHx/WQLRnUNPIGsbTeJGlL J1ABawGyh2XU6yGHvK+Fg9+haAS7ynnBUz7FAFUMLrM9fl9xNc6OZ9CRZ3cAeIx4ljWp vx+A== X-Gm-Message-State: AOAM532d79f+0tP6B310HRLSn6xqoaGvy32su5HymfK4SvYgq2PMMRmS 1M3ihCzc/SCnPgrNPuf7EyrZnPq4uDn4GeTnC5XL X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:7eb5:10bb:834a:d5ec]) (user=axelrasmussen job=sendgmr) by 2002:a5b:c02:: with SMTP id f2mr1895485ybq.234.1621454650549; Wed, 19 May 2021 13:04:10 -0700 (PDT) Date: Wed, 19 May 2021 13:03:39 -0700 In-Reply-To: <20210519200339.829146-1-axelrasmussen@google.com> Message-Id: <20210519200339.829146-11-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210519200339.829146-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.31.1.751.gd2f1c929bd-goog Subject: [PATCH v2 10/10] KVM: selftests: add shared hugetlbfs backing source type From: Axel Rasmussen To: Aaron Lewis , Alexander Graf , Andrew Jones , Andrew Morton , Ben Gardon , Emanuele Giuseppe Esposito , Eric Auger , Jacob Xu , Makarand Sonare , Oliver Upton , Paolo Bonzini , Peter Xu , Shuah Khan , Yanan Wang Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Axel Rasmussen Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This lets us run the demand paging test on top of a shared hugetlbfs-backed area. The "shared" is key, as this allows us to exercise userfaultfd minor faults on hugetlbfs. Signed-off-by: Axel Rasmussen --- tools/testing/selftests/kvm/demand_paging_test.c | 6 ++++-- tools/testing/selftests/kvm/include/test_util.h | 11 +++++++++++ tools/testing/selftests/kvm/lib/kvm_util.c | 9 +++++++-- tools/testing/selftests/kvm/lib/test_util.c | 11 +++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c index df7190261923..60d9b5223b9d 100644 --- a/tools/testing/selftests/kvm/demand_paging_test.c +++ b/tools/testing/selftests/kvm/demand_paging_test.c @@ -485,8 +485,10 @@ int main(int argc, char *argv[]) } } - TEST_ASSERT(p.uffd_mode != UFFDIO_REGISTER_MODE_MINOR || p.src_type == VM_MEM_SRC_SHMEM, - "userfaultfd MINOR mode requires shared memory; pick a different -t"); + if (p.uffd_mode == UFFDIO_REGISTER_MODE_MINOR && + !backing_src_is_shared(p.src_type)) { + TEST_FAIL("userfaultfd MINOR mode requires shared memory; pick a different -t"); + } for_each_guest_mode(run_test, &p); diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h index 7377f00469ef..d79be15dd3d2 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -17,6 +17,7 @@ #include #include #include +#include #include "kselftest.h" static inline int _no_printf(const char *format, ...) { return 0; } @@ -85,6 +86,7 @@ enum vm_mem_backing_src_type { VM_MEM_SRC_ANONYMOUS_HUGETLB_2GB, VM_MEM_SRC_ANONYMOUS_HUGETLB_16GB, VM_MEM_SRC_SHMEM, + VM_MEM_SRC_SHARED_HUGETLB, NUM_SRC_TYPES, }; @@ -101,4 +103,13 @@ size_t get_backing_src_pagesz(uint32_t i); void backing_src_help(void); enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name); +/* + * Whether or not the given source type is shared memory (as opposed to + * anonymous). + */ +static inline bool backing_src_is_shared(enum vm_mem_backing_src_type t) +{ + return vm_mem_backing_src_alias(t)->flag & MAP_SHARED; +} + #endif /* SELFTEST_KVM_TEST_UTIL_H */ diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 0b88d1bbc1e0..8373aec1fb02 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -758,8 +758,13 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, region->mmap_size += alignment; region->fd = -1; - if (src_type == VM_MEM_SRC_SHMEM) { - region->fd = memfd_create("kvm_selftest", MFD_CLOEXEC); + if (backing_src_is_shared(src_type)) { + int memfd_flags = MFD_CLOEXEC; + + if (src_type == VM_MEM_SRC_SHARED_HUGETLB) + memfd_flags |= MFD_HUGETLB; + + region->fd = memfd_create("kvm_selftest", memfd_flags); TEST_ASSERT(region->fd != -1, "memfd_create failed, errno: %i", errno); diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c index c7a265da5090..6ad6c8276b2e 100644 --- a/tools/testing/selftests/kvm/lib/test_util.c +++ b/tools/testing/selftests/kvm/lib/test_util.c @@ -240,6 +240,16 @@ const struct vm_mem_backing_src_alias *vm_mem_backing_src_alias(uint32_t i) .name = "shmem", .flag = MAP_SHARED, }, + [VM_MEM_SRC_SHARED_HUGETLB] = { + .name = "shared_hugetlb", + /* + * No MAP_HUGETLB, we use MFD_HUGETLB instead. Since + * we're using "file backed" memory, we need to specify + * this when the FD is created, not when the area is + * mapped. + */ + .flag = MAP_SHARED, + }, }; _Static_assert(ARRAY_SIZE(aliases) == NUM_SRC_TYPES, "Missing new backing src types?"); @@ -262,6 +272,7 @@ size_t get_backing_src_pagesz(uint32_t i) case VM_MEM_SRC_ANONYMOUS_THP: return get_trans_hugepagesz(); case VM_MEM_SRC_ANONYMOUS_HUGETLB: + case VM_MEM_SRC_SHARED_HUGETLB: return get_def_hugetlb_pagesz(); default: return MAP_HUGE_PAGE_SIZE(flag); -- 2.31.1.751.gd2f1c929bd-goog