[PATCH 06/10] KVM: SVM: Simplify request+kick logic in SNP AP Creation handling

Sean Christopherson posted 10 patches 10 months ago
There is a newer version of this series
[PATCH 06/10] KVM: SVM: Simplify request+kick logic in SNP AP Creation handling
Posted by Sean Christopherson 10 months ago
Drop the local "kick" variable and the unnecessary "fallthrough" logic
from sev_snp_ap_creation(), and simply pivot on the request when deciding
whether or not to immediate force a state update on the target vCPU.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 arch/x86/kvm/svm/sev.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 8425198c5204..7f6c8fedb235 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -3940,7 +3940,6 @@ static int sev_snp_ap_creation(struct vcpu_svm *svm)
 	struct vcpu_svm *target_svm;
 	unsigned int request;
 	unsigned int apic_id;
-	bool kick;
 	int ret;
 
 	request = lower_32_bits(svm->vmcb->control.exit_info_1);
@@ -3958,18 +3957,10 @@ static int sev_snp_ap_creation(struct vcpu_svm *svm)
 
 	target_svm = to_svm(target_vcpu);
 
-	/*
-	 * The target vCPU is valid, so the vCPU will be kicked unless the
-	 * request is for CREATE_ON_INIT.
-	 */
-	kick = true;
-
 	mutex_lock(&target_svm->sev_es.snp_vmsa_mutex);
 
 	switch (request) {
 	case SVM_VMGEXIT_AP_CREATE_ON_INIT:
-		kick = false;
-		fallthrough;
 	case SVM_VMGEXIT_AP_CREATE:
 		if (vcpu->arch.regs[VCPU_REGS_RAX] != sev->vmsa_features) {
 			vcpu_unimpl(vcpu, "vmgexit: mismatched AP sev_features [%#lx] != [%#llx] from guest\n",
@@ -4014,7 +4005,11 @@ static int sev_snp_ap_creation(struct vcpu_svm *svm)
 
 	target_svm->sev_es.snp_ap_waiting_for_reset = true;
 
-	if (kick) {
+	/*
+	 * Unless Creation is deferred until INIT, signal the vCPU to update
+	 * its state.
+	 */
+	if (request != SVM_VMGEXIT_AP_CREATE_ON_INIT) {
 		kvm_make_request(KVM_REQ_UPDATE_PROTECTED_GUEST_STATE, target_vcpu);
 		kvm_vcpu_kick(target_vcpu);
 	}
-- 
2.48.1.601.g30ceb7b040-goog
Re: [PATCH 06/10] KVM: SVM: Simplify request+kick logic in SNP AP Creation handling
Posted by Tom Lendacky 9 months, 3 weeks ago
On 2/18/25 19:27, Sean Christopherson wrote:
> Drop the local "kick" variable and the unnecessary "fallthrough" logic
> from sev_snp_ap_creation(), and simply pivot on the request when deciding
> whether or not to immediate force a state update on the target vCPU.
> 
> No functional change intended.

Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>

> 
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
>  arch/x86/kvm/svm/sev.c | 15 +++++----------
>  1 file changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 8425198c5204..7f6c8fedb235 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -3940,7 +3940,6 @@ static int sev_snp_ap_creation(struct vcpu_svm *svm)
>  	struct vcpu_svm *target_svm;
>  	unsigned int request;
>  	unsigned int apic_id;
> -	bool kick;
>  	int ret;
>  
>  	request = lower_32_bits(svm->vmcb->control.exit_info_1);
> @@ -3958,18 +3957,10 @@ static int sev_snp_ap_creation(struct vcpu_svm *svm)
>  
>  	target_svm = to_svm(target_vcpu);
>  
> -	/*
> -	 * The target vCPU is valid, so the vCPU will be kicked unless the
> -	 * request is for CREATE_ON_INIT.
> -	 */
> -	kick = true;
> -
>  	mutex_lock(&target_svm->sev_es.snp_vmsa_mutex);
>  
>  	switch (request) {
>  	case SVM_VMGEXIT_AP_CREATE_ON_INIT:
> -		kick = false;
> -		fallthrough;
>  	case SVM_VMGEXIT_AP_CREATE:
>  		if (vcpu->arch.regs[VCPU_REGS_RAX] != sev->vmsa_features) {
>  			vcpu_unimpl(vcpu, "vmgexit: mismatched AP sev_features [%#lx] != [%#llx] from guest\n",
> @@ -4014,7 +4005,11 @@ static int sev_snp_ap_creation(struct vcpu_svm *svm)
>  
>  	target_svm->sev_es.snp_ap_waiting_for_reset = true;
>  
> -	if (kick) {
> +	/*
> +	 * Unless Creation is deferred until INIT, signal the vCPU to update
> +	 * its state.
> +	 */
> +	if (request != SVM_VMGEXIT_AP_CREATE_ON_INIT) {
>  		kvm_make_request(KVM_REQ_UPDATE_PROTECTED_GUEST_STATE, target_vcpu);
>  		kvm_vcpu_kick(target_vcpu);
>  	}
Re: [PATCH 06/10] KVM: SVM: Simplify request+kick logic in SNP AP Creation handling
Posted by Gupta, Pankaj 10 months ago
On 2/19/2025 2:27 AM, Sean Christopherson wrote:
> Drop the local "kick" variable and the unnecessary "fallthrough" logic
> from sev_snp_ap_creation(), and simply pivot on the request when deciding
> whether or not to immediate force a state update on the target vCPU.
> 
> No functional change intended.
> 
> Signed-off-by: Sean Christopherson <seanjc@google.com>

Straightforward cleanup.

Reviewed-by: Pankaj Gupta <pankaj.gupta@amd.com>


> ---
>   arch/x86/kvm/svm/sev.c | 15 +++++----------
>   1 file changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 8425198c5204..7f6c8fedb235 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -3940,7 +3940,6 @@ static int sev_snp_ap_creation(struct vcpu_svm *svm)
>   	struct vcpu_svm *target_svm;
>   	unsigned int request;
>   	unsigned int apic_id;
> -	bool kick;
>   	int ret;
>   
>   	request = lower_32_bits(svm->vmcb->control.exit_info_1);
> @@ -3958,18 +3957,10 @@ static int sev_snp_ap_creation(struct vcpu_svm *svm)
>   
>   	target_svm = to_svm(target_vcpu);
>   
> -	/*
> -	 * The target vCPU is valid, so the vCPU will be kicked unless the
> -	 * request is for CREATE_ON_INIT.
> -	 */
> -	kick = true;
> -
>   	mutex_lock(&target_svm->sev_es.snp_vmsa_mutex);
>   
>   	switch (request) {
>   	case SVM_VMGEXIT_AP_CREATE_ON_INIT:
> -		kick = false;
> -		fallthrough;
>   	case SVM_VMGEXIT_AP_CREATE:
>   		if (vcpu->arch.regs[VCPU_REGS_RAX] != sev->vmsa_features) {
>   			vcpu_unimpl(vcpu, "vmgexit: mismatched AP sev_features [%#lx] != [%#llx] from guest\n",
> @@ -4014,7 +4005,11 @@ static int sev_snp_ap_creation(struct vcpu_svm *svm)
>   
>   	target_svm->sev_es.snp_ap_waiting_for_reset = true;
>   
> -	if (kick) {
> +	/*
> +	 * Unless Creation is deferred until INIT, signal the vCPU to update
> +	 * its state.
> +	 */
> +	if (request != SVM_VMGEXIT_AP_CREATE_ON_INIT) {
>   		kvm_make_request(KVM_REQ_UPDATE_PROTECTED_GUEST_STATE, target_vcpu);
>   		kvm_vcpu_kick(target_vcpu);
>   	}