Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1826405pxj; Wed, 19 May 2021 15:06:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzk64UFsvVnKSCJN3sJH94D3eX9Pwq7m0jaRVmCEj4CJm2Vi8XaLYArjJtrQJJsJpZZuTUD X-Received: by 2002:a05:6402:358a:: with SMTP id y10mr1146424edc.65.1621461965846; Wed, 19 May 2021 15:06:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621461965; cv=none; d=google.com; s=arc-20160816; b=wX8Wc0OBREzX2Fi/uwJJ55tUB6Ox7eTXsRJdlSbwsUQTxKOoF4asvsScPdgfZPKyQy QfVJe/OGCbqwKmkRZxp533bnq3Z2fE7I1hXre2WbBBpC0vkBdQTwmYlAOZZrGiifErtz 5W/OCBfXMM/QWkM8APrMDn8gKQBLfRJXQyK2r8B71ZB84p3z7SiED3gDWQeh6xFBJ4bO +soIEIkrkSwPCSjXikJikjDdacJjb59TqB1gulk5ianJy57R5RHEJTNAz9DHFS3Vjjjx uz79SFgIYIX3h3H98XE+3kC6nj8TccpXkPAgjWyzp9SQ1MU1Kab6zBxJe3TYKrz8mrB5 11eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=DHPp5dFe4661NAQ9YjGdxmJrJmUrsmOq7WtKD4ddN7s=; b=kOUdnGuJFuj9hv6VE/7HM0aUzxTd3paeptLeJbYSNaO3Z+LL3oUkVlGiryh00m7hLO QRZVgO49+SW/vbmyDmTwYcaJOE16wfpcJO1fkCLnAviEl4Z2Quh1K2kv7mhvte1joe4w SagiEgwJOrBsM3aQW/Bb+fom0vvGmGve6sVuRqSIfvE7jdw9mCEO2PzaXBNMgxuhU5Fo CVLMFaSVprotzejD1+WYH/E35x0XPEieaPxb1KfEaKrBqnabKeUsq4LoGISrKhMB72Z5 uLV4igiC4XV42SYv2qc9zJNC5SlFKb9ysTxB9bw0SETfCrUEXKf+88X7SG2TcegE0Biu Ybjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HBAODJKK; 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 m1si777272eji.731.2021.05.19.15.05.41; Wed, 19 May 2021 15:06:05 -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=HBAODJKK; 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 S229801AbhESWFT (ORCPT + 99 others); Wed, 19 May 2021 18:05:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229455AbhESWFS (ORCPT ); Wed, 19 May 2021 18:05:18 -0400 Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A66FC061574 for ; Wed, 19 May 2021 15:03:57 -0700 (PDT) Received: by mail-il1-x131.google.com with SMTP id o10so12541456ilm.13 for ; Wed, 19 May 2021 15:03:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DHPp5dFe4661NAQ9YjGdxmJrJmUrsmOq7WtKD4ddN7s=; b=HBAODJKKUijlVggNYGOWYIGxWYk4G+D2MQvWauqSlfji5VEf4ImhXlg1LpWyJRna1o dZmU0Gw1rQJJO5OIiQLZCJn4Qr320bVFgYsttQUdjRzGUJT3hefgjsyQJw9XLxwyzNn3 QpiRssJweEUgRJtKseFmWLxWV+9GpRMVS/k2ZY+KMzeB+gPFbKftJs21nao264aIrMZO r+IN1U0E74zBtNx1nYtfaEkviAqu+s3xKYzkIJK6JyQzY0z+Jop78gMfHcItJtvf6wN5 xmFsDvMU6v/O0zUkLvR2kXTAU1+C/aSybGWM/Ol4hAr7SIJEMq2opG2KHI33H/kWkUP4 QWxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DHPp5dFe4661NAQ9YjGdxmJrJmUrsmOq7WtKD4ddN7s=; b=t5UyZn5pMccfI84YB8SVwHuLTSkkN2JN9DKYTnqrY8yFII++PQ6aFxBnWzK+6I5N4O xwjxUHIOvn0dsHWeNzVwq5SOC8v/pSN4VO4oGZYW3oAboZ1Z/cfvR7ZFrPG+BeKZUG5h i0T8A5rVpcD5EIiUpjk11Dibc1EDOH/bR1IaRHeRltkziqggTKhclUMVf18Dm0CUBq2j NJPSabyU7Nt5DJRstwdyInflPQ2r9zELsXhS8T/p1acPGDpHF3aS5z75nbYNSnwejMkm uplKLgPl/LgA/FdpGrhsvRYJhuWFTz53uS4C/9I5j5cvJBgHw4kjj0jnLll3lTWBnXA9 Uytg== X-Gm-Message-State: AOAM530KHdKAVHZuFmOrt+82Zt/VgZbbkKBRA6ymtITmegRsJUzSKrpI 9KmCav6mK3qkAkP27d9uPvCdA4y69gykaDjRFaAJMg== X-Received: by 2002:a05:6e02:1a49:: with SMTP id u9mr1425014ilv.306.1621461836410; Wed, 19 May 2021 15:03:56 -0700 (PDT) MIME-Version: 1.0 References: <20210519200339.829146-1-axelrasmussen@google.com> <20210519200339.829146-8-axelrasmussen@google.com> In-Reply-To: <20210519200339.829146-8-axelrasmussen@google.com> From: Ben Gardon Date: Wed, 19 May 2021 15:03:45 -0700 Message-ID: Subject: Re: [PATCH v2 07/10] KVM: selftests: add shmem backing source type To: Axel Rasmussen Cc: Aaron Lewis , Alexander Graf , Andrew Jones , Andrew Morton , Emanuele Giuseppe Esposito , Eric Auger , Jacob Xu , Makarand Sonare , Oliver Upton , Paolo Bonzini , Peter Xu , Shuah Khan , Yanan Wang , kvm , LKML , linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 19, 2021 at 1:04 PM Axel Rasmussen wrote: > > 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; Ah I guess this is the corresponding change from the previous patch. > + 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 >