[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y8cmfjRIRp2EphTa@google.com>
Date: Tue, 17 Jan 2023 22:51:42 +0000
From: Sean Christopherson <seanjc@...gle.com>
To: Vishal Annapurve <vannapurve@...gle.com>
Cc: x86@...nel.org, kvm@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-kselftest@...r.kernel.org, pbonzini@...hat.com,
vkuznets@...hat.com, wanpengli@...cent.com, jmattson@...gle.com,
joro@...tes.org, tglx@...utronix.de, mingo@...hat.com,
bp@...en8.de, dave.hansen@...ux.intel.com, hpa@...or.com,
shuah@...nel.org, yang.zhong@...el.com, ricarkol@...gle.com,
aaronlewis@...gle.com, wei.w.wang@...el.com,
kirill.shutemov@...ux.intel.com, corbet@....net, hughd@...gle.com,
jlayton@...nel.org, bfields@...ldses.org,
akpm@...ux-foundation.org, chao.p.peng@...ux.intel.com,
yu.c.zhang@...ux.intel.com, jun.nakajima@...el.com,
dave.hansen@...el.com, michael.roth@....com, qperret@...gle.com,
steven.price@....com, ak@...ux.intel.com, david@...hat.com,
luto@...nel.org, vbabka@...e.cz, marcorr@...gle.com,
erdemaktas@...gle.com, pgonda@...gle.com, nikunj@....com,
diviness@...gle.com, maz@...nel.org, dmatlack@...gle.com,
axelrasmussen@...gle.com, maciej.szmigiero@...cle.com,
mizhang@...gle.com, bgardon@...gle.com, ackerleytng@...gle.com
Subject: Re: [V2 PATCH 4/6] KVM: selftests: x86: Add helpers to execute VMs
with private memory
On Mon, Dec 05, 2022, Vishal Annapurve wrote:
> +void vcpu_run_and_handle_mapgpa(struct kvm_vm *vm, struct kvm_vcpu *vcpu)
> +{
> + /*
> + * Loop until the guest exits with any reason other than
> + * KVM_HC_MAP_GPA_RANGE hypercall.
> + */
> +
> + while (true) {
> + vcpu_run(vcpu);
> +
> + if ((vcpu->run->exit_reason == KVM_EXIT_HYPERCALL) &&
> + (vcpu->run->hypercall.nr == KVM_HC_MAP_GPA_RANGE)) {
I get what you're trying to do, and I completely agree that we need better helpers
and/or macros to reduce this type of boilerplate, but adding a one-off helper like
this is going to be a net negative overall. This helper services exactly one use
case, and also obfuscates what a test does.
In other words, this is yet another thing that needs broad, generic support
(_vcpu_run() is a very special case). E.g. something like this to make it easy
for tests to run a guest and handle ucalls plus specific exits (just a strawman,
I think we can do better for handling ucalls).
#define vcpu_run_loop(vcpu, handlers, ucalls) \
do { \
uint32_t __exit; \
int __r = 0; \
\
while (!r) { \
vcpu_run(vcpu); \
\
__exit = vcpu->run->exit_reason; \
\
if (__exit < ARRAY_SIZE(handlers) && handlers[__exit]) \
__r = handlers[__exit](vcpu); \
else if (__exit == KVM_EXIT_IO && ucalls) \
__r = handle_exit_ucall(vcpu, ucalls, \
ARRAY_SIZE(ucalls)); \
else \
TEST_FAIL(...) \
} \
} while (0)
For this series, I think it makes sense to just open code yet another test. It
really doesn't end up being much code, which is partly why we haven't added
helpers :-/
Powered by blists - more mailing lists