From: Ben Gardon <bgardon@google.com>
To: Axel Rasmussen <axelrasmussen@google.com>
Cc: Aaron Lewis <aaronlewis@google.com>,
Alexander Graf <graf@amazon.com>,
Andrew Jones <drjones@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
Emanuele Giuseppe Esposito <eesposit@redhat.com>,
Eric Auger <eric.auger@redhat.com>,
Jacob Xu <jacobhxu@google.com>,
Makarand Sonare <makarandsonare@google.com>,
Oliver Upton <oupton@google.com>,
Paolo Bonzini <pbonzini@redhat.com>, Peter Xu <peterx@redhat.com>,
Shuah Khan <shuah@kernel.org>,
Yanan Wang <wangyanan55@huawei.com>, kvm <kvm@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v2 06/10] KVM: selftests: refactor vm_mem_backing_src_type flags
Date: Wed, 19 May 2021 15:25:10 -0700 [thread overview]
Message-ID: <CANgfPd-_LgX5bf=GG=_CGHS9gNpeiiuW+_UseoirPuBasWU4tQ@mail.gmail.com> (raw)
In-Reply-To: <CAJHvVchMMse=CcSUnHGDXLKd0YSa3wTvyyyPjT8MU3RmmwAXtQ@mail.gmail.com>
On Wed, May 19, 2021 at 3:17 PM Axel Rasmussen <axelrasmussen@google.com> wrote:
>
> On Wed, May 19, 2021 at 3:02 PM Ben Gardon <bgardon@google.com> wrote:
> >
> > On Wed, May 19, 2021 at 1:04 PM Axel Rasmussen <axelrasmussen@google.com> wrote:
> > >
> > > Each struct vm_mem_backing_src_alias has a flags field, which denotes
> > > the flags used to mmap() an area of that type. Previously, this field
> > > never included MAP_PRIVATE | MAP_ANONYMOUS, because
> > > vm_userspace_mem_region_add assumed that *all* types would always use
> > > those flags, and so it hardcoded them.
> > >
> > > In a follow-up commit, we'll add a new type: shmem. Areas of this type
> > > must not have MAP_PRIVATE | MAP_ANONYMOUS, and instead they must have
> > > MAP_SHARED.
> > >
> > > So, refactor things. Make it so that the flags field of
> > > struct vm_mem_backing_src_alias really is a complete set of flags, and
> > > don't add in any extras in vm_userspace_mem_region_add. This will let us
> > > easily tack on shmem.
> > >
> > > Signed-off-by: Axel Rasmussen <axelrasmussen@google.com>
> > > ---
> > > tools/testing/selftests/kvm/lib/kvm_util.c | 5 ++-
> > > tools/testing/selftests/kvm/lib/test_util.c | 35 +++++++++++----------
> > > 2 files changed, 21 insertions(+), 19 deletions(-)
> > >
> > > diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> > > index 0d6ddee429b9..bc405785ac8b 100644
> > > --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> > > +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> > > @@ -759,9 +759,8 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
> > >
> > > region->mmap_start = mmap(NULL, region->mmap_size,
> > > PROT_READ | PROT_WRITE,
> > > - MAP_PRIVATE | MAP_ANONYMOUS
> > > - | vm_mem_backing_src_alias(src_type)->flag,
> > > - -1, 0);
> > > + vm_mem_backing_src_alias(src_type)->flag,
> > > + region->fd, 0);
> >
> > I don't see the region->fd change mentioned in the patch description
> > or elsewhere in this patch. Is something setting region->fd to -1 or
> > should this be part of another patch in the series?
>
> Ah, apologies, this is a mistake from splitting up the commits. When
> they were all squashed together, we set region->fd = -1 explicitly
> just above here, but with them separated we can't depend on that. I'll
> fix this in a v3.
Thanks for fixing that and thanks for splitting up the patches in this
series. It made them super easy to review.
>
> >
> > > TEST_ASSERT(region->mmap_start != MAP_FAILED,
> > > "test_malloc failed, mmap_start: %p errno: %i",
> > > region->mmap_start, errno);
> > > diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c
> > > index 63d2bc7d757b..06ddde068736 100644
> > > --- a/tools/testing/selftests/kvm/lib/test_util.c
> > > +++ b/tools/testing/selftests/kvm/lib/test_util.c
> > > @@ -168,70 +168,73 @@ size_t get_def_hugetlb_pagesz(void)
> > >
> > > const struct vm_mem_backing_src_alias *vm_mem_backing_src_alias(uint32_t i)
> > > {
> > > + static const int anon_flags = MAP_PRIVATE | MAP_ANONYMOUS;
> > > + static const int anon_huge_flags = anon_flags | MAP_HUGETLB;
> > > +
> > > static const struct vm_mem_backing_src_alias aliases[] = {
> > > [VM_MEM_SRC_ANONYMOUS] = {
> > > .name = "anonymous",
> > > - .flag = 0,
> > > + .flag = anon_flags,
> > > },
> > > [VM_MEM_SRC_ANONYMOUS_THP] = {
> > > .name = "anonymous_thp",
> > > - .flag = 0,
> > > + .flag = anon_flags,
> > > },
> > > [VM_MEM_SRC_ANONYMOUS_HUGETLB] = {
> > > .name = "anonymous_hugetlb",
> > > - .flag = MAP_HUGETLB,
> > > + .flag = anon_huge_flags,
> > > },
> > > [VM_MEM_SRC_ANONYMOUS_HUGETLB_16KB] = {
> > > .name = "anonymous_hugetlb_16kb",
> > > - .flag = MAP_HUGETLB | MAP_HUGE_16KB,
> > > + .flag = anon_huge_flags | MAP_HUGE_16KB,
> > > },
> > > [VM_MEM_SRC_ANONYMOUS_HUGETLB_64KB] = {
> > > .name = "anonymous_hugetlb_64kb",
> > > - .flag = MAP_HUGETLB | MAP_HUGE_64KB,
> > > + .flag = anon_huge_flags | MAP_HUGE_64KB,
> > > },
> > > [VM_MEM_SRC_ANONYMOUS_HUGETLB_512KB] = {
> > > .name = "anonymous_hugetlb_512kb",
> > > - .flag = MAP_HUGETLB | MAP_HUGE_512KB,
> > > + .flag = anon_huge_flags | MAP_HUGE_512KB,
> > > },
> > > [VM_MEM_SRC_ANONYMOUS_HUGETLB_1MB] = {
> > > .name = "anonymous_hugetlb_1mb",
> > > - .flag = MAP_HUGETLB | MAP_HUGE_1MB,
> > > + .flag = anon_huge_flags | MAP_HUGE_1MB,
> > > },
> > > [VM_MEM_SRC_ANONYMOUS_HUGETLB_2MB] = {
> > > .name = "anonymous_hugetlb_2mb",
> > > - .flag = MAP_HUGETLB | MAP_HUGE_2MB,
> > > + .flag = anon_huge_flags | MAP_HUGE_2MB,
> > > },
> > > [VM_MEM_SRC_ANONYMOUS_HUGETLB_8MB] = {
> > > .name = "anonymous_hugetlb_8mb",
> > > - .flag = MAP_HUGETLB | MAP_HUGE_8MB,
> > > + .flag = anon_huge_flags | MAP_HUGE_8MB,
> > > },
> > > [VM_MEM_SRC_ANONYMOUS_HUGETLB_16MB] = {
> > > .name = "anonymous_hugetlb_16mb",
> > > - .flag = MAP_HUGETLB | MAP_HUGE_16MB,
> > > + .flag = anon_huge_flags | MAP_HUGE_16MB,
> > > },
> > > [VM_MEM_SRC_ANONYMOUS_HUGETLB_32MB] = {
> > > .name = "anonymous_hugetlb_32mb",
> > > - .flag = MAP_HUGETLB | MAP_HUGE_32MB,
> > > + .flag = anon_huge_flags | MAP_HUGE_32MB,
> > > },
> > > [VM_MEM_SRC_ANONYMOUS_HUGETLB_256MB] = {
> > > .name = "anonymous_hugetlb_256mb",
> > > - .flag = MAP_HUGETLB | MAP_HUGE_256MB,
> > > + .flag = anon_huge_flags | MAP_HUGE_256MB,
> > > },
> > > [VM_MEM_SRC_ANONYMOUS_HUGETLB_512MB] = {
> > > .name = "anonymous_hugetlb_512mb",
> > > - .flag = MAP_HUGETLB | MAP_HUGE_512MB,
> > > + .flag = anon_huge_flags | MAP_HUGE_512MB,
> > > },
> > > [VM_MEM_SRC_ANONYMOUS_HUGETLB_1GB] = {
> > > .name = "anonymous_hugetlb_1gb",
> > > - .flag = MAP_HUGETLB | MAP_HUGE_1GB,
> > > + .flag = anon_huge_flags | MAP_HUGE_1GB,
> > > },
> > > [VM_MEM_SRC_ANONYMOUS_HUGETLB_2GB] = {
> > > .name = "anonymous_hugetlb_2gb",
> > > - .flag = MAP_HUGETLB | MAP_HUGE_2GB,
> > > + .flag = anon_huge_flags | MAP_HUGE_2GB,
> > > },
> > > [VM_MEM_SRC_ANONYMOUS_HUGETLB_16GB] = {
> > > .name = "anonymous_hugetlb_16gb",
> > > - .flag = MAP_HUGETLB | MAP_HUGE_16GB,
> > > + .flag = anon_huge_flags | MAP_HUGE_16GB,
> > > },
> > > };
> > > _Static_assert(ARRAY_SIZE(aliases) == NUM_SRC_TYPES,
> > > --
> > > 2.31.1.751.gd2f1c929bd-goog
> > >
next prev parent reply other threads:[~2021-05-19 22:25 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-19 20:03 [PATCH v2 00/10] KVM: selftests: exercise userfaultfd minor faults Axel Rasmussen
2021-05-19 20:03 ` [PATCH v2 01/10] KVM: selftests: trivial comment/logging fixes Axel Rasmussen
2021-05-19 21:41 ` Ben Gardon
2021-05-19 20:03 ` [PATCH v2 02/10] KVM: selftests: simplify setup_demand_paging error handling Axel Rasmussen
2021-05-19 21:45 ` Ben Gardon
2021-05-19 22:14 ` Axel Rasmussen
2021-05-19 22:23 ` Ben Gardon
2021-05-24 13:25 ` Paolo Bonzini
2021-05-19 20:03 ` [PATCH v2 03/10] KVM: selftests: print a message when skipping KVM tests Axel Rasmussen
2021-05-19 21:49 ` Ben Gardon
2021-05-24 13:23 ` Paolo Bonzini
2021-05-19 20:03 ` [PATCH v2 04/10] KVM: selftests: compute correct demand paging size Axel Rasmussen
2021-05-19 21:51 ` Ben Gardon
2021-05-19 20:03 ` [PATCH v2 05/10] KVM: selftests: allow different backing source types Axel Rasmussen
2021-05-19 21:53 ` Ben Gardon
2021-05-19 20:03 ` [PATCH v2 06/10] KVM: selftests: refactor vm_mem_backing_src_type flags Axel Rasmussen
2021-05-19 22:02 ` Ben Gardon
2021-05-19 22:16 ` Axel Rasmussen
2021-05-19 22:25 ` Ben Gardon [this message]
2021-05-19 20:03 ` [PATCH v2 07/10] KVM: selftests: add shmem backing source type Axel Rasmussen
2021-05-19 22:03 ` Ben Gardon
2021-05-19 20:03 ` [PATCH v2 08/10] KVM: selftests: create alias mappings when using shared memory Axel Rasmussen
2021-05-25 23:49 ` David Matlack
2021-05-26 17:22 ` Axel Rasmussen
2021-05-26 18:31 ` Paolo Bonzini
2021-05-19 20:03 ` [PATCH v2 09/10] KVM: selftests: allow using UFFD minor faults for demand paging Axel Rasmussen
2021-05-19 22:20 ` Ben Gardon
2021-05-19 22:34 ` Axel Rasmussen
2021-05-24 13:36 ` Paolo Bonzini
2021-05-19 20:03 ` [PATCH v2 10/10] KVM: selftests: add shared hugetlbfs backing source type Axel Rasmussen
2021-05-19 22:22 ` Ben Gardon
2021-05-24 13:38 ` [PATCH v2 00/10] KVM: selftests: exercise userfaultfd minor faults Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CANgfPd-_LgX5bf=GG=_CGHS9gNpeiiuW+_UseoirPuBasWU4tQ@mail.gmail.com' \
--to=bgardon@google.com \
--cc=aaronlewis@google.com \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=drjones@redhat.com \
--cc=eesposit@redhat.com \
--cc=eric.auger@redhat.com \
--cc=graf@amazon.com \
--cc=jacobhxu@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=makarandsonare@google.com \
--cc=oupton@google.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=shuah@kernel.org \
--cc=wangyanan55@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).