Re: [PATCH 28/28] KVM: nSVM: enable GMET for guests

From: mlevitsk

Date: Tue Jun 02 2026 - 10:47:18 EST


On Tue, 2026-05-05 at 21:52 +0200, Paolo Bonzini wrote:
> All that needs to be done is moving the GMET bit from vmcb12 to vmcb02.
> The only new thing is that __nested_copy_vmcb_control_to_cache now
> ensures that ignored-if-unavailable bits are zero in svm->nested.ctl.
>
> Tested-by: David Riley <d.riley@xxxxxxxxxxx>
> Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>

Hi!

Tiny nitpick: Should the patch title be 'KVM: nSVM: enable GMET for nested guests'?
(I know that there is nSVM in the title, but still I was a bit confused about it, at first)


> ---
>  arch/x86/kvm/svm/nested.c | 6 +++++-
>  arch/x86/kvm/svm/svm.c    | 3 +++
>  2 files changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
> index 74a1df1cb84f..3d1fd1776e19 100644
> --- a/arch/x86/kvm/svm/nested.c
> +++ b/arch/x86/kvm/svm/nested.c
> @@ -489,11 +489,14 @@ void __nested_copy_vmcb_control_to_cache(struct kvm_vcpu *vcpu,
>   nested_svm_sanitize_intercept(vcpu, to, SKINIT);
>   nested_svm_sanitize_intercept(vcpu, to, RDPRU);
>  
> - /* Always clear SVM_MISC_ENABLE_NP if the guest cannot use NPTs */
> + /* Always clear misc_ctl bits that the guest cannot use */
>   to->misc_ctl = from->misc_ctl;
>   if (!guest_cpu_cap_has(vcpu, X86_FEATURE_NPT))
>   to->misc_ctl &= ~SVM_MISC_ENABLE_NP;
>  
> + if (!gmet_enabled || !guest_cpu_cap_has(vcpu, X86_FEATURE_GMET))
> + to->misc_ctl &= ~SVM_MISC_ENABLE_GMET;
> +
>   to->iopm_base_pa        = from->iopm_base_pa & PAGE_MASK;
>   to->msrpm_base_pa       = from->msrpm_base_pa & PAGE_MASK;
>   to->tsc_offset          = from->tsc_offset;
> @@ -898,6 +901,7 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm)
>   /* Use vmcb01 MMU and format if guest does not use nNPT */
>   if (nested_npt_enabled(svm)) {
>   vmcb02->control.misc_ctl &= ~SVM_MISC_ENABLE_GMET;
> + vmcb02->control.misc_ctl |= (svm->nested.ctl.misc_ctl & SVM_MISC_ENABLE_GMET);
>  
>   nested_svm_init_mmu_context(vcpu);
>   }
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index fd79874c5f4b..a82471a6d3ea 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -5504,6 +5504,9 @@ static __init void svm_set_cpu_caps(void)
>   if (boot_cpu_has(X86_FEATURE_PFTHRESHOLD))
>   kvm_cpu_cap_set(X86_FEATURE_PFTHRESHOLD);
>  
> + if (gmet_enabled)
> + kvm_cpu_cap_set(X86_FEATURE_GMET);
> +
>   if (vgif)
>   kvm_cpu_cap_set(X86_FEATURE_VGIF);
>  

Looks good otherwise.

Reviewed-by: Maxim Levitsky <mlevitsk@xxxxxxxxxx>

Best regards,
Maxim Levitsky