All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Andrey Smetanin <asmetanin@virtuozzo.com>, kvm@vger.kernel.org
Cc: Gleb Natapov <gleb@kernel.org>, Joerg Roedel <joro@8bytes.org>,
	"K. Y. Srinivasan" <kys@microsoft.com>,
	Haiyang Zhang <haiyangz@microsoft.com>,
	Roman Kagan <rkagan@virtuozzo.com>,
	"Denis V. Lunev" <den@openvz.org>,
	qemu-devel@nongnu.org
Subject: Re: [PATCH v1 4/5] kvm/x86: Hyper-V VMBus hypercall userspace exit
Date: Wed, 20 Jan 2016 14:43:01 +0100	[thread overview]
Message-ID: <569F8EE5.7010500@redhat.com> (raw)
In-Reply-To: <1452595842-20880-5-git-send-email-asmetanin@virtuozzo.com>



On 12/01/2016 11:50, Andrey Smetanin wrote:
> The patch implements KVM_EXIT_HV_HCALL functionality
> for Hyper-V VMBus hypercalls: HV_X64_HCALL_POST_MESSAGE,
> HV_X64_HCALL_SIGNAL_EVENT.
> 
> Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
> Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
> CC: Gleb Natapov <gleb@kernel.org>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Joerg Roedel <joro@8bytes.org>
> CC: "K. Y. Srinivasan" <kys@microsoft.com>
> CC: Haiyang Zhang <haiyangz@microsoft.com>
> CC: Roman Kagan <rkagan@virtuozzo.com>
> CC: Denis V. Lunev <den@openvz.org>
> CC: qemu-devel@nongnu.org
> ---
>  Documentation/virtual/kvm/api.txt |  8 ++++++++
>  arch/x86/kvm/hyperv.c             | 28 +++++++++++++++++++++-------
>  arch/x86/kvm/hyperv.h             |  1 +
>  arch/x86/kvm/x86.c                |  3 +++
>  include/uapi/linux/kvm.h          |  7 +++++++
>  5 files changed, 40 insertions(+), 7 deletions(-)
> 
> diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
> index 053f613..23d4b9d 100644
> --- a/Documentation/virtual/kvm/api.txt
> +++ b/Documentation/virtual/kvm/api.txt
> @@ -3359,6 +3359,14 @@ Hyper-V SynIC state change. Notification is used to remap SynIC
>  event/message pages and to enable/disable SynIC messages/events processing
>  in userspace.
>  
> +		/* KVM_EXIT_HYPERV_HCALL */
> +		struct {
> +			__u64 input;
> +			__u64 params[2];
> +			__u64 result;
> +		} hv_hcall;
> +Indicates that the VCPU exits into userspace to process some guest
> +Hyper-V hypercalls.

Is this something other than KVM_EXIT_HYPERV because of the previous
discussion about MSRs?  Otherwise, it definitely should be a separate
type of the existing KVM_EXIT_HYPERV exit.

(In fact, I do not think anymore that I will add the MSR exit in 4.5.
It's kind of against the KVM design to do "CPU things" outside the
kernel.  My conjecture is that MSRs are either simple and thus not
security sensitive, or complicated and thus require state that resides
in the kernel).

>  		/* Fix the size of the union. */
>  		char padding[256];
>  	};
> diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
> index 0e7c90f..76c9ec4 100644
> --- a/arch/x86/kvm/hyperv.c
> +++ b/arch/x86/kvm/hyperv.c
> @@ -1087,18 +1087,32 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
>  	case HV_X64_HCALL_NOTIFY_LONG_SPIN_WAIT:
>  		kvm_vcpu_on_spin(vcpu);
>  		break;
> +	case HV_X64_HCALL_POST_MESSAGE:
> +	case HV_X64_HCALL_SIGNAL_EVENT:
> +		vcpu->run->exit_reason = KVM_EXIT_HYPERV_HCALL;
> +		vcpu->run->hv_hcall.input = param;
> +		vcpu->run->hv_hcall.params[0] = ingpa;
> +		vcpu->run->hv_hcall.params[1] = outgpa;
> +		return 0;
>  	default:
>  		res = HV_STATUS_INVALID_HYPERCALL_CODE;
>  		break;
>  	}
>  
>  	ret = res | (((u64)rep_done & 0xfff) << 32);
> -	if (longmode) {
> -		kvm_register_write(vcpu, VCPU_REGS_RAX, ret);
> -	} else {
> -		kvm_register_write(vcpu, VCPU_REGS_RDX, ret >> 32);
> -		kvm_register_write(vcpu, VCPU_REGS_RAX, ret & 0xffffffff);
> -	}
> -
> +	kvm_hv_hypercall_set_result(vcpu, ret);
>  	return 1;
>  }
> +
> +void kvm_hv_hypercall_set_result(struct kvm_vcpu *vcpu, u64 result)
> +{
> +	bool longmode;
> +
> +	longmode = is_64_bit_mode(vcpu);
> +	if (longmode)
> +		kvm_register_write(vcpu, VCPU_REGS_RAX, result);
> +	else {
> +		kvm_register_write(vcpu, VCPU_REGS_RDX, result >> 32);
> +		kvm_register_write(vcpu, VCPU_REGS_RAX, result & 0xffffffff);
> +	}
> +}
> diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h
> index 60eccd4..64a4a3b 100644
> --- a/arch/x86/kvm/hyperv.h
> +++ b/arch/x86/kvm/hyperv.h
> @@ -52,6 +52,7 @@ int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata);
>  
>  bool kvm_hv_hypercall_enabled(struct kvm *kvm);
>  int kvm_hv_hypercall(struct kvm_vcpu *vcpu);
> +void kvm_hv_hypercall_set_result(struct kvm_vcpu *vcpu, u64 result);
>  
>  void kvm_hv_irq_routing_update(struct kvm *kvm);
>  int kvm_hv_synic_set_irq(struct kvm *kvm, u32 vcpu_id, u32 sint);
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index fad1d09..6ad3599 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -6886,6 +6886,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
>  	} else
>  		WARN_ON(vcpu->arch.pio.count || vcpu->mmio_needed);
>  
> +	if (unlikely(kvm_run->exit_reason == KVM_EXIT_HYPERV_HCALL))
> +		kvm_hv_hypercall_set_result(vcpu, kvm_run->hv_hcall.result);
> +
>  	r = vcpu_run(vcpu);
>  
>  out:
> diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
> index 9da9051..a62c4fb 100644
> --- a/include/uapi/linux/kvm.h
> +++ b/include/uapi/linux/kvm.h
> @@ -199,6 +199,7 @@ struct kvm_hyperv_exit {
>  #define KVM_EXIT_S390_STSI        25
>  #define KVM_EXIT_IOAPIC_EOI       26
>  #define KVM_EXIT_HYPERV           27
> +#define KVM_EXIT_HYPERV_HCALL     28
>  
>  /* For KVM_EXIT_INTERNAL_ERROR */
>  /* Emulate instruction failed. */
> @@ -355,6 +356,12 @@ struct kvm_run {
>  		} eoi;
>  		/* KVM_EXIT_HYPERV */
>  		struct kvm_hyperv_exit hyperv;
> +		/* KVM_EXIT_HYPERV_HCALL */
> +		struct {
> +			__u64 input;
> +			__u64 params[2];
> +			__u64 result;

Please put result before params, so that it's possible to add more
parameters in the future.

Paolo

> +		} hv_hcall;
>  		/* Fix the size of the union. */
>  		char padding[256];
>  	};
> 

WARNING: multiple messages have this Message-ID (diff)
From: Paolo Bonzini <pbonzini@redhat.com>
To: Andrey Smetanin <asmetanin@virtuozzo.com>, kvm@vger.kernel.org
Cc: Gleb Natapov <gleb@kernel.org>, Joerg Roedel <joro@8bytes.org>,
	qemu-devel@nongnu.org, Roman Kagan <rkagan@virtuozzo.com>,
	"Denis V. Lunev" <den@openvz.org>,
	"K. Y. Srinivasan" <kys@microsoft.com>,
	Haiyang Zhang <haiyangz@microsoft.com>
Subject: Re: [Qemu-devel] [PATCH v1 4/5] kvm/x86: Hyper-V VMBus hypercall userspace exit
Date: Wed, 20 Jan 2016 14:43:01 +0100	[thread overview]
Message-ID: <569F8EE5.7010500@redhat.com> (raw)
In-Reply-To: <1452595842-20880-5-git-send-email-asmetanin@virtuozzo.com>



On 12/01/2016 11:50, Andrey Smetanin wrote:
> The patch implements KVM_EXIT_HV_HCALL functionality
> for Hyper-V VMBus hypercalls: HV_X64_HCALL_POST_MESSAGE,
> HV_X64_HCALL_SIGNAL_EVENT.
> 
> Signed-off-by: Andrey Smetanin <asmetanin@virtuozzo.com>
> Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
> CC: Gleb Natapov <gleb@kernel.org>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Joerg Roedel <joro@8bytes.org>
> CC: "K. Y. Srinivasan" <kys@microsoft.com>
> CC: Haiyang Zhang <haiyangz@microsoft.com>
> CC: Roman Kagan <rkagan@virtuozzo.com>
> CC: Denis V. Lunev <den@openvz.org>
> CC: qemu-devel@nongnu.org
> ---
>  Documentation/virtual/kvm/api.txt |  8 ++++++++
>  arch/x86/kvm/hyperv.c             | 28 +++++++++++++++++++++-------
>  arch/x86/kvm/hyperv.h             |  1 +
>  arch/x86/kvm/x86.c                |  3 +++
>  include/uapi/linux/kvm.h          |  7 +++++++
>  5 files changed, 40 insertions(+), 7 deletions(-)
> 
> diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
> index 053f613..23d4b9d 100644
> --- a/Documentation/virtual/kvm/api.txt
> +++ b/Documentation/virtual/kvm/api.txt
> @@ -3359,6 +3359,14 @@ Hyper-V SynIC state change. Notification is used to remap SynIC
>  event/message pages and to enable/disable SynIC messages/events processing
>  in userspace.
>  
> +		/* KVM_EXIT_HYPERV_HCALL */
> +		struct {
> +			__u64 input;
> +			__u64 params[2];
> +			__u64 result;
> +		} hv_hcall;
> +Indicates that the VCPU exits into userspace to process some guest
> +Hyper-V hypercalls.

Is this something other than KVM_EXIT_HYPERV because of the previous
discussion about MSRs?  Otherwise, it definitely should be a separate
type of the existing KVM_EXIT_HYPERV exit.

(In fact, I do not think anymore that I will add the MSR exit in 4.5.
It's kind of against the KVM design to do "CPU things" outside the
kernel.  My conjecture is that MSRs are either simple and thus not
security sensitive, or complicated and thus require state that resides
in the kernel).

>  		/* Fix the size of the union. */
>  		char padding[256];
>  	};
> diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
> index 0e7c90f..76c9ec4 100644
> --- a/arch/x86/kvm/hyperv.c
> +++ b/arch/x86/kvm/hyperv.c
> @@ -1087,18 +1087,32 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
>  	case HV_X64_HCALL_NOTIFY_LONG_SPIN_WAIT:
>  		kvm_vcpu_on_spin(vcpu);
>  		break;
> +	case HV_X64_HCALL_POST_MESSAGE:
> +	case HV_X64_HCALL_SIGNAL_EVENT:
> +		vcpu->run->exit_reason = KVM_EXIT_HYPERV_HCALL;
> +		vcpu->run->hv_hcall.input = param;
> +		vcpu->run->hv_hcall.params[0] = ingpa;
> +		vcpu->run->hv_hcall.params[1] = outgpa;
> +		return 0;
>  	default:
>  		res = HV_STATUS_INVALID_HYPERCALL_CODE;
>  		break;
>  	}
>  
>  	ret = res | (((u64)rep_done & 0xfff) << 32);
> -	if (longmode) {
> -		kvm_register_write(vcpu, VCPU_REGS_RAX, ret);
> -	} else {
> -		kvm_register_write(vcpu, VCPU_REGS_RDX, ret >> 32);
> -		kvm_register_write(vcpu, VCPU_REGS_RAX, ret & 0xffffffff);
> -	}
> -
> +	kvm_hv_hypercall_set_result(vcpu, ret);
>  	return 1;
>  }
> +
> +void kvm_hv_hypercall_set_result(struct kvm_vcpu *vcpu, u64 result)
> +{
> +	bool longmode;
> +
> +	longmode = is_64_bit_mode(vcpu);
> +	if (longmode)
> +		kvm_register_write(vcpu, VCPU_REGS_RAX, result);
> +	else {
> +		kvm_register_write(vcpu, VCPU_REGS_RDX, result >> 32);
> +		kvm_register_write(vcpu, VCPU_REGS_RAX, result & 0xffffffff);
> +	}
> +}
> diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h
> index 60eccd4..64a4a3b 100644
> --- a/arch/x86/kvm/hyperv.h
> +++ b/arch/x86/kvm/hyperv.h
> @@ -52,6 +52,7 @@ int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata);
>  
>  bool kvm_hv_hypercall_enabled(struct kvm *kvm);
>  int kvm_hv_hypercall(struct kvm_vcpu *vcpu);
> +void kvm_hv_hypercall_set_result(struct kvm_vcpu *vcpu, u64 result);
>  
>  void kvm_hv_irq_routing_update(struct kvm *kvm);
>  int kvm_hv_synic_set_irq(struct kvm *kvm, u32 vcpu_id, u32 sint);
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index fad1d09..6ad3599 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -6886,6 +6886,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
>  	} else
>  		WARN_ON(vcpu->arch.pio.count || vcpu->mmio_needed);
>  
> +	if (unlikely(kvm_run->exit_reason == KVM_EXIT_HYPERV_HCALL))
> +		kvm_hv_hypercall_set_result(vcpu, kvm_run->hv_hcall.result);
> +
>  	r = vcpu_run(vcpu);
>  
>  out:
> diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
> index 9da9051..a62c4fb 100644
> --- a/include/uapi/linux/kvm.h
> +++ b/include/uapi/linux/kvm.h
> @@ -199,6 +199,7 @@ struct kvm_hyperv_exit {
>  #define KVM_EXIT_S390_STSI        25
>  #define KVM_EXIT_IOAPIC_EOI       26
>  #define KVM_EXIT_HYPERV           27
> +#define KVM_EXIT_HYPERV_HCALL     28
>  
>  /* For KVM_EXIT_INTERNAL_ERROR */
>  /* Emulate instruction failed. */
> @@ -355,6 +356,12 @@ struct kvm_run {
>  		} eoi;
>  		/* KVM_EXIT_HYPERV */
>  		struct kvm_hyperv_exit hyperv;
> +		/* KVM_EXIT_HYPERV_HCALL */
> +		struct {
> +			__u64 input;
> +			__u64 params[2];
> +			__u64 result;

Please put result before params, so that it's possible to add more
parameters in the future.

Paolo

> +		} hv_hcall;
>  		/* Fix the size of the union. */
>  		char padding[256];
>  	};
> 

  parent reply	other threads:[~2016-01-20 16:20 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-12 10:50 [PATCH v1 0/5] KVM: Hyper-V VMBus hypercalls Andrey Smetanin
2016-01-12 10:50 ` [Qemu-devel] " Andrey Smetanin
2016-01-12 10:50 ` [PATCH v1 1/5] kvm/x86: Rename Hyper-V long spin wait hypercall Andrey Smetanin
2016-01-12 10:50   ` [Qemu-devel] " Andrey Smetanin
2016-01-12 10:50 ` [PATCH v1 2/5] drivers/hv: Move VMBus hypercall codes into Hyper-V UAPI header Andrey Smetanin
2016-01-12 10:50   ` [Qemu-devel] " Andrey Smetanin
2016-01-20 15:04   ` KY Srinivasan
2016-01-20 15:04     ` [Qemu-devel] " KY Srinivasan
2016-01-12 10:50 ` [PATCH v1 3/5] kvm/x86: Pass return code of kvm_emulate_hypercall Andrey Smetanin
2016-01-12 10:50   ` [Qemu-devel] " Andrey Smetanin
2016-01-12 10:50 ` [PATCH v1 4/5] kvm/x86: Hyper-V VMBus hypercall userspace exit Andrey Smetanin
2016-01-12 10:50   ` [Qemu-devel] " Andrey Smetanin
2016-01-14  8:30   ` Pavel Fedin
2016-01-14  8:30     ` [Qemu-devel] " Pavel Fedin
2016-01-14 10:20     ` 'Roman Kagan'
2016-01-14 10:20       ` [Qemu-devel] " 'Roman Kagan'
2016-01-14 10:50       ` Pavel Fedin
2016-01-14 10:50         ` [Qemu-devel] " Pavel Fedin
2016-01-14 11:52         ` 'Roman Kagan'
2016-01-14 11:52           ` [Qemu-devel] " 'Roman Kagan'
2016-01-20 13:59     ` Paolo Bonzini
2016-01-20 13:59       ` [Qemu-devel] " Paolo Bonzini
2016-01-20 14:41       ` Pavel Fedin
2016-01-20 14:41         ` [Qemu-devel] " Pavel Fedin
2016-01-20 15:20       ` 'Roman Kagan'
2016-01-20 15:20         ` [Qemu-devel] " 'Roman Kagan'
2016-01-20 17:02         ` Paolo Bonzini
2016-01-20 17:02           ` [Qemu-devel] " Paolo Bonzini
2016-01-20 17:31           ` 'Roman Kagan'
2016-01-20 17:31             ` [Qemu-devel] " 'Roman Kagan'
2016-01-20 21:05             ` Paolo Bonzini
2016-01-20 21:05               ` [Qemu-devel] " Paolo Bonzini
2016-01-20 13:43   ` Paolo Bonzini [this message]
2016-01-20 13:43     ` Paolo Bonzini
2016-01-20 16:51     ` Roman Kagan
2016-01-20 16:51       ` [Qemu-devel] " Roman Kagan
2016-01-12 10:50 ` [PATCH v1 5/5] kvm/x86: Reject Hyper-V hypercall continuation Andrey Smetanin
2016-01-12 10:50   ` [Qemu-devel] " Andrey Smetanin
2016-01-12 11:19 ` [PATCH v1 0/5] KVM: Hyper-V VMBus hypercalls Andrey Smetanin
2016-01-12 11:19   ` [Qemu-devel] " Andrey Smetanin
2016-01-19  7:49 ` Denis V. Lunev
2016-01-19  7:49   ` [Qemu-devel] " Denis V. Lunev
2016-01-19 16:47   ` Paolo Bonzini
2016-01-19 16:47     ` [Qemu-devel] " Paolo Bonzini
2016-01-20 14:08     ` Paolo Bonzini
2016-01-20 14:08       ` [Qemu-devel] " Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=569F8EE5.7010500@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=asmetanin@virtuozzo.com \
    --cc=den@openvz.org \
    --cc=gleb@kernel.org \
    --cc=haiyangz@microsoft.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=kys@microsoft.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rkagan@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.