Re: [PATCH 00/13] KVM: x86: Add a cap to disable NX hugepages on a VM

From: Ben Gardon
Date: Thu Mar 10 2022 - 14:29:33 EST


On Thu, Mar 10, 2022 at 11:58 AM Sean Christopherson <seanjc@xxxxxxxxxx> wrote:
>
> On Thu, Mar 10, 2022, Ben Gardon wrote:
> > selftests: KVM: Wrap memslot IDs in a struct for readability
> > selftests: KVM: Add memslot parameter to VM vaddr allocation
> > selftests: KVM: Add memslot parameter to elf_load
>
> I really, really, don't want to go down this path of proliferating memslot crud
> throughout the virtual memory allocators. I would much rather we solve this by
> teaching the VM creation helpers to (optionally) use hugepages. The amount of
> churn required just so that one test can back code with hugepages is absurd, and
> there's bound to be tests in the future that want to force hugepages as well.

I agree that proliferating the memslots argument isn't strictly
required for this test, but doing so makes it much easier to make
assertions about hugepage counts and such because you don't have your
stacks and page tables backed with hugepages.

Those patches are a lot of churn, but at least to me, they make the
code much more readable. Currently there are many functions which just
pass along 0 for the memslot, and often have multiple other numerical
arguments, which makes it hard to understand what the function is
doing.

I don't think explicitly specifying memslots really adds that much
overhead to the tests, and I'd rather have control over that than
implicitly cramming everything into memslot 0.

If you have a better way to manage the memslots and create virtual
mappings for / load code into other memslots, I'm open to it, but we
should do something about it.