diff mbox series

[v2,1/6] KVM: x86: hyper-v: Use common code for hypercall userspace exit

Message ID 20221121234026.3037083-2-vipinsh@google.com (mailing list archive)
State New, archived
Headers show
Series Add Hyper-v extended hypercall support in KVM | expand

Commit Message

Vipin Sharma Nov. 21, 2022, 11:40 p.m. UTC
Remove duplicate code to exit to userspace for hyper-v hypercalls and
use a common place to exit.

Signed-off-by: Vipin Sharma <vipinsh@google.com>
Suggested-by: Sean Christopherson <seanjc@google.com>
---
 arch/x86/kvm/hyperv.c | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

Comments

Vitaly Kuznetsov Nov. 22, 2022, 4:04 p.m. UTC | #1
Vipin Sharma <vipinsh@google.com> writes:

> Remove duplicate code to exit to userspace for hyper-v hypercalls and
> use a common place to exit.
>

"No functional change intended." as it was suggested by Sean :-)

> Signed-off-by: Vipin Sharma <vipinsh@google.com>
> Suggested-by: Sean Christopherson <seanjc@google.com>
> ---
>  arch/x86/kvm/hyperv.c | 27 +++++++++++----------------
>  1 file changed, 11 insertions(+), 16 deletions(-)
>
> diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
> index 2c7f2a26421e..0b6964ed2e66 100644
> --- a/arch/x86/kvm/hyperv.c
> +++ b/arch/x86/kvm/hyperv.c
> @@ -2503,14 +2503,7 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
>  			ret = HV_STATUS_INVALID_HYPERCALL_INPUT;
>  			break;
>  		}
> -		vcpu->run->exit_reason = KVM_EXIT_HYPERV;
> -		vcpu->run->hyperv.type = KVM_EXIT_HYPERV_HCALL;
> -		vcpu->run->hyperv.u.hcall.input = hc.param;
> -		vcpu->run->hyperv.u.hcall.params[0] = hc.ingpa;
> -		vcpu->run->hyperv.u.hcall.params[1] = hc.outgpa;
> -		vcpu->arch.complete_userspace_io =
> -				kvm_hv_hypercall_complete_userspace;
> -		return 0;
> +		goto hypercall_userspace_exit;
>  	case HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST:
>  		if (unlikely(hc.var_cnt)) {
>  			ret = HV_STATUS_INVALID_HYPERCALL_INPUT;
> @@ -2569,14 +2562,7 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
>  			ret = HV_STATUS_OPERATION_DENIED;
>  			break;
>  		}
> -		vcpu->run->exit_reason = KVM_EXIT_HYPERV;
> -		vcpu->run->hyperv.type = KVM_EXIT_HYPERV_HCALL;
> -		vcpu->run->hyperv.u.hcall.input = hc.param;
> -		vcpu->run->hyperv.u.hcall.params[0] = hc.ingpa;
> -		vcpu->run->hyperv.u.hcall.params[1] = hc.outgpa;
> -		vcpu->arch.complete_userspace_io =
> -				kvm_hv_hypercall_complete_userspace;
> -		return 0;
> +		goto hypercall_userspace_exit;
>  	}
>  	default:
>  		ret = HV_STATUS_INVALID_HYPERCALL_CODE;
> @@ -2585,6 +2571,15 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
>  
>  hypercall_complete:
>  	return kvm_hv_hypercall_complete(vcpu, ret);
> +
> +hypercall_userspace_exit:
> +	vcpu->run->exit_reason = KVM_EXIT_HYPERV;
> +	vcpu->run->hyperv.type = KVM_EXIT_HYPERV_HCALL;
> +	vcpu->run->hyperv.u.hcall.input = hc.param;
> +	vcpu->run->hyperv.u.hcall.params[0] = hc.ingpa;
> +	vcpu->run->hyperv.u.hcall.params[1] = hc.outgpa;
> +	vcpu->arch.complete_userspace_io = kvm_hv_hypercall_complete_userspace;
> +	return 0;
>  }
>  
>  void kvm_hv_init_vm(struct kvm *kvm)

Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Sean Christopherson Nov. 22, 2022, 7:58 p.m. UTC | #2
On Tue, Nov 22, 2022, Vitaly Kuznetsov wrote:
> Vipin Sharma <vipinsh@google.com> writes:
> 
> > Remove duplicate code to exit to userspace for hyper-v hypercalls and
> > use a common place to exit.
> >
> 
> "No functional change intended." as it was suggested by Sean :-)

Heh, I need to find a way to collect royalties.
Vipin Sharma Nov. 23, 2022, 8:01 p.m. UTC | #3
On Tue, Nov 22, 2022 at 11:58 AM Sean Christopherson <seanjc@google.com> wrote:
>
> On Tue, Nov 22, 2022, Vitaly Kuznetsov wrote:
> > Vipin Sharma <vipinsh@google.com> writes:
> >
> > > Remove duplicate code to exit to userspace for hyper-v hypercalls and
> > > use a common place to exit.
> > >
> >
> > "No functional change intended." as it was suggested by Sean :-)
>
> Heh, I need to find a way to collect royalties.


Suffixed with a ®
diff mbox series

Patch

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 2c7f2a26421e..0b6964ed2e66 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -2503,14 +2503,7 @@  int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
 			ret = HV_STATUS_INVALID_HYPERCALL_INPUT;
 			break;
 		}
-		vcpu->run->exit_reason = KVM_EXIT_HYPERV;
-		vcpu->run->hyperv.type = KVM_EXIT_HYPERV_HCALL;
-		vcpu->run->hyperv.u.hcall.input = hc.param;
-		vcpu->run->hyperv.u.hcall.params[0] = hc.ingpa;
-		vcpu->run->hyperv.u.hcall.params[1] = hc.outgpa;
-		vcpu->arch.complete_userspace_io =
-				kvm_hv_hypercall_complete_userspace;
-		return 0;
+		goto hypercall_userspace_exit;
 	case HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST:
 		if (unlikely(hc.var_cnt)) {
 			ret = HV_STATUS_INVALID_HYPERCALL_INPUT;
@@ -2569,14 +2562,7 @@  int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
 			ret = HV_STATUS_OPERATION_DENIED;
 			break;
 		}
-		vcpu->run->exit_reason = KVM_EXIT_HYPERV;
-		vcpu->run->hyperv.type = KVM_EXIT_HYPERV_HCALL;
-		vcpu->run->hyperv.u.hcall.input = hc.param;
-		vcpu->run->hyperv.u.hcall.params[0] = hc.ingpa;
-		vcpu->run->hyperv.u.hcall.params[1] = hc.outgpa;
-		vcpu->arch.complete_userspace_io =
-				kvm_hv_hypercall_complete_userspace;
-		return 0;
+		goto hypercall_userspace_exit;
 	}
 	default:
 		ret = HV_STATUS_INVALID_HYPERCALL_CODE;
@@ -2585,6 +2571,15 @@  int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
 
 hypercall_complete:
 	return kvm_hv_hypercall_complete(vcpu, ret);
+
+hypercall_userspace_exit:
+	vcpu->run->exit_reason = KVM_EXIT_HYPERV;
+	vcpu->run->hyperv.type = KVM_EXIT_HYPERV_HCALL;
+	vcpu->run->hyperv.u.hcall.input = hc.param;
+	vcpu->run->hyperv.u.hcall.params[0] = hc.ingpa;
+	vcpu->run->hyperv.u.hcall.params[1] = hc.outgpa;
+	vcpu->arch.complete_userspace_io = kvm_hv_hypercall_complete_userspace;
+	return 0;
 }
 
 void kvm_hv_init_vm(struct kvm *kvm)