KVM Archive mirror
 help / color / mirror / Atom feed
From: "Huang, Kai" <kai.huang@intel.com>
To: "pbonzini@redhat.com" <pbonzini@redhat.com>,
	"seanjc@google.com" <seanjc@google.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 3/3] KVM: x86: Explicitly zero kvm_caps during vendor module load
Date: Wed, 24 Apr 2024 03:25:45 +0000	[thread overview]
Message-ID: <8e3ad8fa55a26d8726ef0b68e40f59cbcdac1f6c.camel@intel.com> (raw)
In-Reply-To: <20240423165328.2853870-4-seanjc@google.com>

On Tue, 2024-04-23 at 09:53 -0700, Sean Christopherson wrote:
> Zero out all of kvm_caps when loading a new vendor module to ensure that
> KVM can't inadvertently rely on global initialization of a field, and add
> a comment above the definition of kvm_caps to call out that all fields
> needs to be explicitly computed during vendor module load.
> 
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
>  arch/x86/kvm/x86.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 44ce187bad89..8f3979d5fc80 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -92,6 +92,11 @@
>  #define MAX_IO_MSRS 256
>  #define KVM_MAX_MCE_BANKS 32
>  
> +/*
> + * Note, kvm_caps fields should *never* have default values, all fields must be
> + * recomputed from scratch during vendor module load, e.g. to account for a
> + * vendor module being reloaded with different module parameters.
> + */
>  struct kvm_caps kvm_caps __read_mostly;
>  EXPORT_SYMBOL_GPL(kvm_caps);
>  
> @@ -9755,6 +9760,8 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops)
>  		return -EIO;
>  	}
>  
> +	memset(&kvm_caps, 0, sizeof(kvm_caps));
> +
>  	x86_emulator_cache = kvm_alloc_emulator_cache();
>  	if (!x86_emulator_cache) {
>  		pr_err("failed to allocate cache for x86 emulator\n");

Why do the memset() here particularly?

Isn't it better to put ...

	memset(&kvm_caps, 0, sizeof(kvm_caps));
	kvm_caps.supported_vm_types = BIT(KVM_X86_DEFAULT_VM);
	kvm_caps.supported_mce_cap = MCG_CTL_P | MCG_SER_P;

... together so it can be easily seen?

We can even have a helper to do above to "reset kvm_caps to default
values" I think.



  reply	other threads:[~2024-04-24  3:25 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-23 16:53 [PATCH 0/3] KVM: x86: Fix supported VM_TYPES caps Sean Christopherson
2024-04-23 16:53 ` [PATCH 1/3] KVM: x86: Fully re-initialize supported_vm_types on vendor module load Sean Christopherson
2024-04-23 16:53 ` [PATCH 2/3] KVM: x86: Fully re-initialize supported_mce_cap " Sean Christopherson
2024-04-23 16:53 ` [PATCH 3/3] KVM: x86: Explicitly zero kvm_caps during " Sean Christopherson
2024-04-24  3:25   ` Huang, Kai [this message]
2024-04-24 15:33     ` Sean Christopherson
2024-04-25 10:07       ` Huang, Kai
2024-04-25 13:43 ` [PATCH 0/3] KVM: x86: Fix supported VM_TYPES caps Xiaoyao Li
2024-04-25 14:30   ` Sean Christopherson
2024-04-26  1:17     ` Huang, Kai
2024-04-26 15:47       ` Sean Christopherson
2024-04-29  2:45         ` Huang, Kai
2024-04-29 15:56           ` Sean Christopherson
2024-05-07 17:20             ` Paolo Bonzini
2024-05-07 17:08 ` Paolo Bonzini
2024-05-10 14:50 ` 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=8e3ad8fa55a26d8726ef0b68e40f59cbcdac1f6c.camel@intel.com \
    --to=kai.huang@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.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 read-only IMAP folder(s) and NNTP newsgroup(s).