Re: [PATCH v2 3/4] KVM: nVMX: Track whether changes in L0 require MSR bitmap for L2 to be rebuilt

From: Sean Christopherson
Date: Fri Oct 08 2021 - 19:54:41 EST


On Mon, Oct 04, 2021, Vitaly Kuznetsov wrote:
> Introduce a flag to keep track of whether MSR bitmap for L2 needs to be
> rebuilt due to changes in MSR bitmap for L1 or switching to a different
> L2. This information will be used for Enlightened MSR Bitmap feature for
> Hyper-V guests.
>
> Note, setting msr_bitmap_changed to 'true' from set_current_vmptr() is
> not really needed for Enlightened MSR Bitmap as the feature can only
> be used in conjunction with Enlightened VMCS but let's keep tracking
> information complete, it's cheap and in the future similar PV feature can
> easily be implemented for KVM on KVM too.
>
> No functional change intended.
>
> Signed-off-by: Vitaly Kuznetsov <vkuznets@xxxxxxxxxx>
> ---

...

> void vmx_disable_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr, int type)
> diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h
> index 592217fd7d92..eb7a1697bec2 100644
> --- a/arch/x86/kvm/vmx/vmx.h
> +++ b/arch/x86/kvm/vmx/vmx.h
> @@ -148,6 +148,12 @@ struct nested_vmx {
> bool need_vmcs12_to_shadow_sync;
> bool dirty_vmcs12;
>
> + /*
> + * Indicates whether MSR bitmap for L2 needs to be rebuilt due to
> + * changes in MSR bitmap for L1 or switching to a different L2.
> + */
> + bool msr_bitmap_changed;

This is misleading, and arguably wrong. It's only accurate when used in conjuction
with a paravirt L1 that states if a VMCS has a dirty MSR bitmap. E.g. this flag
will be wrong if L1 changes the address of the bitmap in the VMCS, and it's
obviously wrong if L1 changes the MSR bitmap itself.

The changelog kind of covers that, but those details will be completely lost to
readers of the code.

Would it be illegal from KVM to simply clear the CLEAN bit in the eVMCS at the
appropriate points?

> +
> /*
> * Indicates lazily loaded guest state has not yet been decached from
> * vmcs02.
> --
> 2.31.1
>