Received: by 2002:a05:6520:4211:b029:f4:110d:56bc with SMTP id o17csp1585090lkv; Wed, 19 May 2021 13:23:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCylNubhupVV6lzCZRNOSK92Vs/eAHWfT++mSm7xwOHukYdMcAn+SmtHpcWHatVUmzXtxa X-Received: by 2002:a6b:b48a:: with SMTP id d132mr1506740iof.167.1621455816266; Wed, 19 May 2021 13:23:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621455816; cv=none; d=google.com; s=arc-20160816; b=WPNhlc0C3CtK2CIfXJ2pvbwqwS60+nzvforS1oWX3oV+MTYgErqc7SMfIVHEIDMHi3 15azCWkeVfe/d6NtJK4z934o9kkCgAyh8DV5fL+4sM2LyFafT8WUGoN7RB5+3NhCkDkN EQdkh5U+nlKC7Ax8AlyHmOlTxpNcRbS3bZ5DkjGp2T+Z93BbOGBAhPFNhlMcretKTRB2 g9ArUUGcIvLOAKPFIE1B/NQ74WgHP73Z1tl/npvCLBajiq7PmPxtCWCaWaruCx+/gOPf fULlkO5CESZI10JgLGOH7jaS6zR8EhoMDny2cT+9jq9I9tM31rdqJROqgByX1FMiE3Zs +VYQ== 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=HFkF1APt128Gb87FitaIP1LHWqXE7g4u5TT6f2wQ4F0=; b=BRGvVExLiXrWLIjWjRCBrh33hVZhVGfoI6M5oNkhio5XApFQ/gn58NoDaeH0EFF/b6 PB9CtOe5HAcGUa3Z8EcLwtRIdi41GLRQY5No2MiEtG7PnE8yYFjL4rEagseonHv7VbZ7 sLNcR5un1vhqJMgrUkeYr7lhBKlrXKlltJS8pRpfRIZFN4tGr3aPyNKAFqyp1xAsKshy L2s1jc3pVpTmYlfS+mmATSwFoGgSNw4oHqzOoYSLEZs+Lq91T3YRmoe307531Ml9x28i K9WbMRdNqRIx0QVRcjHLK4ydiQYGdgayXP4oQXHMXXEbT3nFUAnx845vaK9XDydC8oKH LjwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=WOlaU86H; 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 f4si620727ilj.107.2021.05.19.13.23.22; Wed, 19 May 2021 13:23:36 -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=WOlaU86H; 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 S232957AbhESUFi (ORCPT + 99 others); Wed, 19 May 2021 16:05:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232854AbhESUFY (ORCPT ); Wed, 19 May 2021 16:05:24 -0400 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1983C061763 for ; Wed, 19 May 2021 13:04:02 -0700 (PDT) Received: by mail-qv1-xf49.google.com with SMTP id n12-20020a0c8c0c0000b02901edb8963d4dso11295193qvb.18 for ; Wed, 19 May 2021 13:04:02 -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=HFkF1APt128Gb87FitaIP1LHWqXE7g4u5TT6f2wQ4F0=; b=WOlaU86HU/1wiYQFXxW5ZuNPd81yF5F3h/5AfU4FJMy585nY5GOaPe77m4ekQ2FSrh Mv1mHaP6YHLsueVlI1yCyW3fcfmDJhldtTmpq+lMSD2IHAB0XtXNJASRoqZFSYaq57Bp wLlitL1XcNBkcfgcuhYX4y1ZgGDdQbuTE9utqumoUpXb5wIOpXGhqsvI//9lOFNnn+VM FP1l14uYKc9N56P9Kd4qsiQGMawv//GlPha5iLE5JfkesYSpfIxNEWBndm1rssByWTmT AXv1jV99VT+M6wWwBTKZfP4CMQaXW/dzMkmkQQoN5iR3emQbm1JcdnbBNf4k03KUyKEB m4EQ== 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=HFkF1APt128Gb87FitaIP1LHWqXE7g4u5TT6f2wQ4F0=; b=Go0N3UwjF5wjZDWI9t0j9cenCMFLn75qG97nW7fCNZLZUpgM3UPPrR8hd1CXDg2Gsu KopQ+0GbAwYzwkukkmEzzu0nLMJlxjWytlyxnEqxBXvrITFko0kt3dZ/ju58euDDkiyD X+Iyq1KA3GBUms9tvFPHb47M/gW62jmLVRPtOxUQL/YRVLAjBUgKMSYO2aK43ruP+rHP yJzIptiqUlq9aXZgY4YRgJ6GLtD1KgK5r0+iH2c9DINgMmAx9IBrWPMAR/oVkImmPngC 4iDZ8eC5WzfjZ0YKxoVVqlQAIDTjLzDEdbDrXRVipJ3e7Wt0ZGJH7PSZvQrnRvyMPMb4 6C+w== X-Gm-Message-State: AOAM5306xebIa1QGrJGjgZKd6RDbDWRz4MZiAt12NKbu8j4PKY7315FE qoKMBNOzd/V0KGA6uuRfkEXqSAJEHXl0uuV7pU0r X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:7eb5:10bb:834a:d5ec]) (user=axelrasmussen job=sendgmr) by 2002:a0c:e709:: with SMTP id d9mr1270050qvn.19.1621454641916; Wed, 19 May 2021 13:04:01 -0700 (PDT) Date: Wed, 19 May 2021 13:03:36 -0700 In-Reply-To: <20210519200339.829146-1-axelrasmussen@google.com> Message-Id: <20210519200339.829146-8-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 07/10] KVM: selftests: add shmem 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 shmem-backed area. In follow-up commits, we'll 1) leverage this new capability to create an alias mapping, and then 2) use the alias mapping to exercise UFFD minor faults. Signed-off-by: Axel Rasmussen --- tools/testing/selftests/kvm/include/test_util.h | 1 + tools/testing/selftests/kvm/lib/kvm_util.c | 15 +++++++++++++++ tools/testing/selftests/kvm/lib/test_util.c | 5 +++++ 3 files changed, 21 insertions(+) diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h index fade3130eb01..7377f00469ef 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -84,6 +84,7 @@ enum vm_mem_backing_src_type { VM_MEM_SRC_ANONYMOUS_HUGETLB_1GB, VM_MEM_SRC_ANONYMOUS_HUGETLB_2GB, VM_MEM_SRC_ANONYMOUS_HUGETLB_16GB, + VM_MEM_SRC_SHMEM, NUM_SRC_TYPES, }; diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index bc405785ac8b..e4a8d0c43c5e 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -757,6 +757,21 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, if (alignment > 1) region->mmap_size += alignment; + region->fd = -1; + if (src_type == VM_MEM_SRC_SHMEM) { + region->fd = memfd_create("kvm_selftest", MFD_CLOEXEC); + TEST_ASSERT(region->fd != -1, + "memfd_create failed, errno: %i", errno); + + ret = ftruncate(region->fd, region->mmap_size); + TEST_ASSERT(ret == 0, "ftruncate failed, errno: %i", errno); + + ret = fallocate(region->fd, + FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, + region->mmap_size); + TEST_ASSERT(ret == 0, "fallocate failed, errno: %i", errno); + } + region->mmap_start = mmap(NULL, region->mmap_size, PROT_READ | PROT_WRITE, vm_mem_backing_src_alias(src_type)->flag, diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c index 06ddde068736..c7a265da5090 100644 --- a/tools/testing/selftests/kvm/lib/test_util.c +++ b/tools/testing/selftests/kvm/lib/test_util.c @@ -236,6 +236,10 @@ const struct vm_mem_backing_src_alias *vm_mem_backing_src_alias(uint32_t i) .name = "anonymous_hugetlb_16gb", .flag = anon_huge_flags | MAP_HUGE_16GB, }, + [VM_MEM_SRC_SHMEM] = { + .name = "shmem", + .flag = MAP_SHARED, + }, }; _Static_assert(ARRAY_SIZE(aliases) == NUM_SRC_TYPES, "Missing new backing src types?"); @@ -253,6 +257,7 @@ size_t get_backing_src_pagesz(uint32_t i) switch (i) { case VM_MEM_SRC_ANONYMOUS: + case VM_MEM_SRC_SHMEM: return getpagesize(); case VM_MEM_SRC_ANONYMOUS_THP: return get_trans_hugepagesz(); -- 2.31.1.751.gd2f1c929bd-goog