diff mbox series

KVM: SNP: Fix LBR Virtualization for SNP guest

Message ID 20240605114810.1304-1-ravi.bangoria@amd.com (mailing list archive)
State New, archived
Headers show
Series KVM: SNP: Fix LBR Virtualization for SNP guest | expand

Commit Message

Ravi Bangoria June 5, 2024, 11:48 a.m. UTC
SEV-ES and thus SNP guest mandates LBR Virtualization to be _always_ ON.
Although commit b7e4be0a224f ("KVM: SEV-ES: Delegate LBR virtualization
to the processor") did the correct change for SEV-ES guests, it missed
the SNP. Fix it.

Reported-by: Srikanth Aithal <sraithal@amd.com>
Fixes: b7e4be0a224f ("KVM: SEV-ES: Delegate LBR virtualization to the processor")
Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com>
---
- SNP support was not present while I prepared the original patches and
  that lead to this confusion. Sorry about that.

 arch/x86/kvm/svm/sev.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Paolo Bonzini June 5, 2024, 11:50 a.m. UTC | #1
On Wed, Jun 5, 2024 at 1:49 PM Ravi Bangoria <ravi.bangoria@amd.com> wrote:
>
> SEV-ES and thus SNP guest mandates LBR Virtualization to be _always_ ON.
> Although commit b7e4be0a224f ("KVM: SEV-ES: Delegate LBR virtualization
> to the processor") did the correct change for SEV-ES guests, it missed
> the SNP. Fix it.
>
> Reported-by: Srikanth Aithal <sraithal@amd.com>
> Fixes: b7e4be0a224f ("KVM: SEV-ES: Delegate LBR virtualization to the processor")
> Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com>
> ---
> - SNP support was not present while I prepared the original patches and
>   that lead to this confusion. Sorry about that.

No problem, this is a semantic conflict and your original patches will
go in 6.10. Applied to kvm/next.

Paolo

>  arch/x86/kvm/svm/sev.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 7d401f8a3001..57291525e084 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -2395,6 +2395,14 @@ static int snp_launch_update_vmsa(struct kvm *kvm, struct kvm_sev_cmd *argp)
>                 }
>
>                 svm->vcpu.arch.guest_state_protected = true;
> +               /*
> +                * SEV-ES (and thus SNP) guest mandates LBR Virtualization to
> +                * be _always_ ON. Enable it only after setting
> +                * guest_state_protected because KVM_SET_MSRS allows dynamic
> +                * toggling of LBRV (for performance reason) on write access to
> +                * MSR_IA32_DEBUGCTLMSR when guest_state_protected is not set.
> +                */
> +               svm_enable_lbrv(vcpu);
>         }
>
>         return 0;
> --
> 2.45.1
>
Aithal, Srikanth June 5, 2024, 11:52 a.m. UTC | #2
On 6/5/2024 5:18 PM, Ravi Bangoria wrote:
> SEV-ES and thus SNP guest mandates LBR Virtualization to be _always_ ON.
> Although commit b7e4be0a224f ("KVM: SEV-ES: Delegate LBR virtualization
> to the processor") did the correct change for SEV-ES guests, it missed
> the SNP. Fix it.
>
> Reported-by: Srikanth Aithal <sraithal@amd.com>
> Fixes: b7e4be0a224f ("KVM: SEV-ES: Delegate LBR virtualization to the processor")
> Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com>
> ---
> - SNP support was not present while I prepared the original patches and
>    that lead to this confusion. Sorry about that.
>
>   arch/x86/kvm/svm/sev.c | 8 ++++++++
>   1 file changed, 8 insertions(+)
>
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 7d401f8a3001..57291525e084 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -2395,6 +2395,14 @@ static int snp_launch_update_vmsa(struct kvm *kvm, struct kvm_sev_cmd *argp)
>   		}
>   
>   		svm->vcpu.arch.guest_state_protected = true;
> +		/*
> +		 * SEV-ES (and thus SNP) guest mandates LBR Virtualization to
> +		 * be _always_ ON. Enable it only after setting
> +		 * guest_state_protected because KVM_SET_MSRS allows dynamic
> +		 * toggling of LBRV (for performance reason) on write access to
> +		 * MSR_IA32_DEBUGCTLMSR when guest_state_protected is not set.
> +		 */
> +		svm_enable_lbrv(vcpu);
>   	}
>   
>   	return 0;
Tested-by: Srikanth Aithal <sraithal@amd.com>
diff mbox series

Patch

diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 7d401f8a3001..57291525e084 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -2395,6 +2395,14 @@  static int snp_launch_update_vmsa(struct kvm *kvm, struct kvm_sev_cmd *argp)
 		}
 
 		svm->vcpu.arch.guest_state_protected = true;
+		/*
+		 * SEV-ES (and thus SNP) guest mandates LBR Virtualization to
+		 * be _always_ ON. Enable it only after setting
+		 * guest_state_protected because KVM_SET_MSRS allows dynamic
+		 * toggling of LBRV (for performance reason) on write access to
+		 * MSR_IA32_DEBUGCTLMSR when guest_state_protected is not set.
+		 */
+		svm_enable_lbrv(vcpu);
 	}
 
 	return 0;