From: David Matlack <dmatlack@google.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Erdem Aktas <erdemaktas@google.com>,
linux-kselftest@vger.kernel.org, Peter Gonda <pgonda@google.com>,
Marc Orr <marcorr@google.com>, Sagi Shahar <sagis@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Shuah Khan <shuah@kernel.org>, Andrew Jones <drjones@redhat.com>,
Ben Gardon <bgardon@google.com>, Peter Xu <peterx@redhat.com>,
Emanuele Giuseppe Esposito <eesposit@redhat.com>,
Christian Borntraeger <borntraeger@de.ibm.com>,
Ricardo Koller <ricarkol@google.com>,
Eric Auger <eric.auger@redhat.com>,
Yanan Wang <wangyanan55@huawei.com>,
Aaron Lewis <aaronlewis@google.com>,
Jim Mattson <jmattson@google.com>,
Oliver Upton <oupton@google.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Peter Shier <pshier@google.com>,
Axel Rasmussen <axelrasmussen@google.com>,
Zhenzhong Duan <zhenzhong.duan@intel.com>,
"Maciej S. Szmigiero" <maciej.szmigiero@oracle.com>,
Like Xu <like.xu@linux.intel.com>,
open list <linux-kernel@vger.kernel.org>,
"open list:KERNEL VIRTUAL MACHINE (KVM)" <kvm@vger.kernel.org>
Subject: Re: [RFC PATCH 1/4] KVM: selftests: Add support for creating non-default type VMs
Date: Wed, 28 Jul 2021 16:07:19 +0000 [thread overview]
Message-ID: <YQGAtxWqBhBUYWBN@google.com> (raw)
In-Reply-To: <YQBw8BIcCAq5ybHr@google.com>
On Tue, Jul 27, 2021 at 08:47:44PM +0000, Sean Christopherson wrote:
> On Mon, Jul 26, 2021, David Matlack wrote:
> > On Mon, Jul 26, 2021 at 11:37:54AM -0700, Erdem Aktas wrote:
> > > Currently vm_create function only creates KVM_X86_LEGACY_VM type VMs.
> > > Changing the vm_create function to accept type parameter to create
> > > new VM types.
> > >
> > > Signed-off-by: Erdem Aktas <erdemaktas@google.com>
> > > Reviewed-by: Sean Christopherson <seanjc@google.com>
>
> *-by tags should not be added unless explicitly provided. IIRC, our internal
> gerrit will convert +1 to Reviewed-by, but I don't think that's the case here.
> This applies to all patches in this series.
>
> See "Using Reported-by:, Tested-by:, Reviewed-by:, Suggested-by: and Fixes:" in
> Documentation/process/submitting-patches.rst for more info.
>
> > > Reviewed-by: Peter Gonda <pgonda@google.com>
> > > Reviewed-by: Marc Orr <marcorr@google.com>
> > > Reviewed-by: Sagi Shahar <sagis@google.com>
> >
> > Reviewed-by: David Matlack <dmatlack@google.com>
> >
> > (aside from the nit below)
> >
> > > ---
> > > .../testing/selftests/kvm/include/kvm_util.h | 1 +
> > > tools/testing/selftests/kvm/lib/kvm_util.c | 29 +++++++++++++++++--
> > > 2 files changed, 27 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h
> > > index d53bfadd2..c63df42d6 100644
> > > --- a/tools/testing/selftests/kvm/include/kvm_util.h
> > > +++ b/tools/testing/selftests/kvm/include/kvm_util.h
> > > @@ -88,6 +88,7 @@ int vcpu_enable_cap(struct kvm_vm *vm, uint32_t vcpu_id,
> > > void vm_enable_dirty_ring(struct kvm_vm *vm, uint32_t ring_size);
> > >
> > > struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm);
> > > +struct kvm_vm *__vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm, int type);
> >
> > nit: Consider using a more readable function name such as
> > vm_create_with_type().
>
> Ha! This is why I don't like doing internal reviews :-D
+1 :)
>
> Erdem originally had vm_create_type(), I suggested __vm_create() as the double
> underscore scheme is more common in the kernel for cases where there's a default
> wrapper and an inner helper that implements the full API.
>
> Convention aside, the argument againsts ...with_type() are that it doesn't scale,
> e.g. if someone adds another parameter parameter for which vm_create() provides a
> default, and it doesn't self-document the relationship between vm_create() and
> the inner helper, e.g. by convention, based on names alone I know that vm_create()
> likely is a wrapper around __vm_create().
True, although with __vm_create() is not solving the scalability
problem, it's just preventing scaling altogether (you can only have 1
wrapper function, vm_create). So if any caller wants to override one of
the defaults they have to override all of them.
I agree with you though in this case: __vm_create() is a better choice
(especially given the existence of vm_create_with_vcpus).
A better option than both (but would involve more work) would be to
create an options struct with all optional arguments. Unfortunately C
makes working with options structs a bit clumsy. But it's something to
consider as the number of options passed to __vm_create increases.
For example:
struct vm_options {
enum vm_guest_mode mode;
uint64_t phy_pages;
int perm;
int type;
};
struct kvm_vm *vm_create(const struct vm_options *options)
{
...
}
static const struct vm_options default_vm_options = {
.mode = VM_MODE_DEFAULT,
.phy_pages = DEFAULT_GUEST_PHY_PAGES,
.perm = O_RDWR,
.type = DEFAULT_VM_TYPE,
};
/* Create a VM with default options. */
vm = create_vm(&default_vm_options);
/* Create a VM with TDX enabled. */
struct vm_options options = default_vm_options;
options.type = VM_TYPE_TDX;
vm = create_vm(&options);
(I'm sure I ham-fisted the const stuff but you get the idea.)
I'm toying with introducing an options struct to perf_test_util as well
so this is very top of mind.
>
> Compare that with the existing
>
> vm_create_default_with_vcpus()
> vm_create_default()
> vm_create_with_vcpus()
> vm_create()
>
> where the relationship between all the helpers is not immediately clear, and
> vm_create_with_vcpus() is a misnomer because it does much more than call vm_create()
> and instantiate vCPUs, e.g. it also instantiates the IRQ chip and loads the test
> into guest memory.
next prev parent reply other threads:[~2021-07-28 16:08 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-26 18:37 [RFC PATCH 0/4] TDX KVM selftests Erdem Aktas
2021-07-26 18:37 ` [RFC PATCH 1/4] KVM: selftests: Add support for creating non-default type VMs Erdem Aktas
2021-07-26 22:26 ` David Matlack
2021-07-27 20:47 ` Sean Christopherson
2021-07-28 16:07 ` David Matlack [this message]
2021-07-28 20:11 ` Andrew Jones
2021-08-04 6:09 ` Xiaoyao Li
2021-08-04 14:24 ` Maxim Levitsky
2021-08-04 14:42 ` Xiaoyao Li
2021-08-04 14:45 ` Maxim Levitsky
2021-08-04 20:29 ` Erdem Aktas
2021-08-04 23:31 ` Sean Christopherson
2021-07-26 18:37 ` [RFC PATCH 2/4] KVM: selftest: Add helper functions to create TDX VMs Erdem Aktas
2021-07-26 18:37 ` [RFC PATCH 3/4] KVM: selftest: Adding TDX life cycle test Erdem Aktas
2021-07-26 22:42 ` David Matlack
2021-07-26 18:37 ` [RFC PATCH 4/4] KVM: selftest: Adding test case for TDX port IO Erdem Aktas
2021-07-28 4:02 ` [RFC PATCH 0/4] TDX KVM selftests Duan, Zhenzhong
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=YQGAtxWqBhBUYWBN@google.com \
--to=dmatlack@google.com \
--cc=aaronlewis@google.com \
--cc=axelrasmussen@google.com \
--cc=bgardon@google.com \
--cc=borntraeger@de.ibm.com \
--cc=drjones@redhat.com \
--cc=eesposit@redhat.com \
--cc=erdemaktas@google.com \
--cc=eric.auger@redhat.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=like.xu@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=maciej.szmigiero@oracle.com \
--cc=marcorr@google.com \
--cc=oupton@google.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=pgonda@google.com \
--cc=pshier@google.com \
--cc=ricarkol@google.com \
--cc=sagis@google.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=vkuznets@redhat.com \
--cc=wangyanan55@huawei.com \
--cc=zhenzhong.duan@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.