Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5539513pxv; Wed, 28 Jul 2021 13:13:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYctN7zeTRaePm/eMWNo69LZiydpyrVgU+H1vbVIGzS3aIKkucSKSCvzmDtemCSjR8MXAA X-Received: by 2002:a92:4b0a:: with SMTP id m10mr1006987ilg.163.1627503210551; Wed, 28 Jul 2021 13:13:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627503210; cv=none; d=google.com; s=arc-20160816; b=feezCGCqDB116lY2P1AigSmgVqWQaDTaFW6oq1C6oYxt3lzqWWQNWe3w/4y+sos83g 0Czs61d44x37OzKvRw+u3VnFM9NHsUV9wPkoSpnyAQxnoOXCA32zPf7PSLNU+kHRfGOo nb3VmLdX5Ishd9o6nhsUHPd+AquXOb9ONARpc5B6dyZb0ZqKpjJSLnhxeWc1/wHxiG2F 3GCkW5Stc99IihG8KBK8foKcPqB3TW3LvpwgatH7i47nflbiW6ajUhPSftCz3+pcAKPJ XvcJmYpxj3RIAu5ib/c/JNnyaY+WofeqrMSb+YNi7DtILrFMpvV1lL9TtslzU6Qy4QrE O+fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=qUsQUoIIPoW4dgda1D/9HQ9hF2FFxCPZK19cH6im2dg=; b=Sj0K9p/E6FeFnZbZxe9vLYT/A+FBOCgBiHedRmREpvB12FXNPVhTj9GpFUO4EL00i+ /Zr3UdyrSFHWX8kHvjgZuJCkxnYFgIns5DgJpF2Ru8w6xq1Dgxar5v6ldGzUzONfsRxM FSSyCPx9i9ZdxSwdsok5n4jLx4MtiDNKgrjK3VDFAJ/z/jqewvRRw5ACnErXy63MxphP d1RdX7h87h8tsy7ArXB0/UdTswcrA8K56Vj14r+WNXiouHGgV9mN6r3qkyIis8e1edsL OySs0lhhDIER3/gNHFsmPcnD+hO/vPjyw9QGZCzTGYIUoDX/FK/koQ9sAXm1Z/alZRoo aRrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Qivo5PvJ; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w5si879946ilu.14.2021.07.28.13.13.15; Wed, 28 Jul 2021 13:13:30 -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=@redhat.com header.s=mimecast20190719 header.b=Qivo5PvJ; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231312AbhG1ULt (ORCPT + 99 others); Wed, 28 Jul 2021 16:11:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21392 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231243AbhG1ULt (ORCPT ); Wed, 28 Jul 2021 16:11:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627503106; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=qUsQUoIIPoW4dgda1D/9HQ9hF2FFxCPZK19cH6im2dg=; b=Qivo5PvJ07Mj31KMn5M7PNZt3o17FyuDCXak2Iql/kxmJr08zrnTkYMvHrLdtLgxzKkWJZ dNVIzUzpNDQwNqfVmGqmc1ueP1sv1PNt9Qg1sWK+OeOoq1csNN8BllqpIyI0EvpvZDYF/G sO5meuoq88631TZMfWDgRT67laGzouk= Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-517-3kzrnsOVMs2zqnUhpJXkrw-1; Wed, 28 Jul 2021 16:11:45 -0400 X-MC-Unique: 3kzrnsOVMs2zqnUhpJXkrw-1 Received: by mail-io1-f72.google.com with SMTP id l9-20020a6b70090000b02904df6556dad4so2450310ioc.0 for ; Wed, 28 Jul 2021 13:11:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=qUsQUoIIPoW4dgda1D/9HQ9hF2FFxCPZK19cH6im2dg=; b=PZ1NYttvQGiH8TpSNAyGpRAdHbcNwuszbYVi6VIXdUBAkGQxY392QbpsQk1xq6DQSP VtllZlP4eHECI8yicU2LBy1zymFCgyeufFdXbw1W+cUaP/gXSCClC/LRSJu9trchjFl6 8e4jCS8S24BKFq93A4XIS7TVy5sp16KpI0VDXXiN1Dl0erTPpsDgUnvExk4QEad9tdrg 23xlij1jgmE5no8GAwohAD2oBWaRM5z+BFiDyrcBANUVZk+y+TUtOT5PSK55UNP1Z77s +mW6pn7YqgN0xQKXsprx+Dl+0MlJZ+1u8OOKuJjYVDmJ7I6fvFUJ8TeB2in672gpDjhG pkFw== X-Gm-Message-State: AOAM532fvVJnWoRC1jnfA1MqG4+5Y06YyD8X5UTxhEC3pXvK/WSI/DR8 Wn8Q1Vj6yoEKx29mH42ZjKfNO7mko/kVVA/2DPSfyq0B24Yn89Kvep9WEi2y9xHj+2+62LQvc0b 4QLIRWGVeiuD9l62YDiJRTeqR X-Received: by 2002:a6b:ee16:: with SMTP id i22mr959858ioh.37.1627503105079; Wed, 28 Jul 2021 13:11:45 -0700 (PDT) X-Received: by 2002:a6b:ee16:: with SMTP id i22mr959842ioh.37.1627503104862; Wed, 28 Jul 2021 13:11:44 -0700 (PDT) Received: from gator ([140.82.166.162]) by smtp.gmail.com with ESMTPSA id m23sm873807ioj.5.2021.07.28.13.11.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 13:11:44 -0700 (PDT) Date: Wed, 28 Jul 2021 22:11:41 +0200 From: Andrew Jones To: David Matlack Cc: Sean Christopherson , Erdem Aktas , linux-kselftest@vger.kernel.org, Peter Gonda , Marc Orr , Sagi Shahar , Paolo Bonzini , Shuah Khan , Ben Gardon , Peter Xu , Emanuele Giuseppe Esposito , Christian Borntraeger , Ricardo Koller , Eric Auger , Yanan Wang , Aaron Lewis , Jim Mattson , Oliver Upton , Vitaly Kuznetsov , Peter Shier , Axel Rasmussen , Zhenzhong Duan , "Maciej S. Szmigiero" , Like Xu , open list , "open list:KERNEL VIRTUAL MACHINE (KVM)" Subject: Re: [RFC PATCH 1/4] KVM: selftests: Add support for creating non-default type VMs Message-ID: <20210728201141.6quhfym7tbg2dier@gator> References: <20210726183816.1343022-1-erdemaktas@google.com> <20210726183816.1343022-2-erdemaktas@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 28, 2021 at 04:07:19PM +0000, David Matlack wrote: > 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 > > > > Reviewed-by: Sean Christopherson > > > > *-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 > > > > Reviewed-by: Marc Orr > > > > Reviewed-by: Sagi Shahar > > > > > > Reviewed-by: David Matlack > > > > > > (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 like this. Thanks, drew