Linux-HyperV Archive on lore.kernel.org
 help / color / Atom feed
From: Roman Kagan <rvkagan@yandex-team.ru>
To: Jon Doron <arilou@gmail.com>
Cc: kvm@vger.kernel.org, linux-hyperv@vger.kernel.org, vkuznets@redhat.com
Subject: Re: [PATCH v11 5/7] x86/kvm/hyper-v: enable hypercalls without hypercall page with syndbg
Date: Wed, 13 May 2020 12:57:38 +0300
Message-ID: <20200513095738.GC29650@rvkaganb.lan> (raw)
In-Reply-To: <20200424113746.3473563-6-arilou@gmail.com>

On Fri, Apr 24, 2020 at 02:37:44PM +0300, Jon Doron wrote:
> Microsoft's kdvm.dll dbgtransport module does not respect the hypercall
> page and simply identifies the CPU being used (AMD/Intel) and according
> to it simply makes hypercalls with the relevant instruction
> (vmmcall/vmcall respectively).
> 
> The relevant function in kdvm is KdHvConnectHypervisor which first checks
> if the hypercall page has been enabled via HV_X64_MSR_HYPERCALL_ENABLE,
> and in case it was not it simply sets the HV_X64_MSR_GUEST_OS_ID to
> 0x1000101010001 which means:
> build_number = 0x0001
> service_version = 0x01
> minor_version = 0x01
> major_version = 0x01
> os_id = 0x00 (Undefined)
> vendor_id = 1 (Microsoft)
> os_type = 0 (A value of 0 indicates a proprietary, closed source OS)
> 
> and starts issuing the hypercall without setting the hypercall page.

I guess this is to avoid interfering with the OS being debugged
requesting its own hypercall page at a different address.

> To resolve this issue simply enable hypercalls also if the guest_os_id
> is not 0 and the syndbg feature is enabled.
> 
> Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> Signed-off-by: Jon Doron <arilou@gmail.com>
> ---
>  arch/x86/kvm/hyperv.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
> index 435516595090..524b5466a515 100644
> --- a/arch/x86/kvm/hyperv.c
> +++ b/arch/x86/kvm/hyperv.c
> @@ -1650,7 +1650,10 @@ static u64 kvm_hv_send_ipi(struct kvm_vcpu *current_vcpu, u64 ingpa, u64 outgpa,
>  
>  bool kvm_hv_hypercall_enabled(struct kvm *kvm)
>  {
> -	return READ_ONCE(kvm->arch.hyperv.hv_hypercall) & HV_X64_MSR_HYPERCALL_ENABLE;
> +	struct kvm_hv *hv = &kvm->arch.hyperv;
> +
> +	return READ_ONCE(hv->hv_hypercall) & HV_X64_MSR_HYPERCALL_ENABLE ||
> +	       (hv->hv_syndbg.active && READ_ONCE(hv->hv_guest_os_id) != 0);

This function is meant to tell if the hypercall should be interpreted as
following KVM or HyperV conventions.  Quoting from the spec

  3.5 Legal Hypercall Environments

  ...
  All hypercalls should be invoked through the architecturally-defined
  hypercall interface. (See the following sections for instructions on
  discovering and establishing this interface.) An attempt to invoke a
  hypercall by any other means (for example, copying the code from the
  hypercall code page to an alternate location and executing it from
  there) might result in an undefined operation (#UD) exception.  The
  hypervisor is not guaranteed to deliver this exception.

so I think we can simply test for hv_guest_os_id != 0 and ignore
HV_X64_MSR_HYPERCALL_ENABLE (it's about hypercall page being enabled,
not the hypercalls per se).

Thanks,
Roman.

>  }
>  
>  static void kvm_hv_hypercall_set_result(struct kvm_vcpu *vcpu, u64 result)
> -- 
> 2.24.1
> 

  reply index

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-24 11:37 [PATCH v11 0/7] x86/kvm/hyper-v: add support for synthetic debugger Jon Doron
2020-04-24 11:37 ` [PATCH v11 1/7] x86/kvm/hyper-v: Explicitly align hcall param for kvm_hyperv_exit Jon Doron
2020-05-13  8:42   ` Roman Kagan
2020-04-24 11:37 ` [PATCH v11 2/7] x86/kvm/hyper-v: Simplify addition for custom cpuid leafs Jon Doron
2020-05-13  9:24   ` Roman Kagan
2020-05-13 12:49     ` Jon Doron
2020-05-29 11:13       ` Paolo Bonzini
2020-04-24 11:37 ` [PATCH v11 3/7] x86/hyper-v: Add synthetic debugger definitions Jon Doron
2020-04-24 11:37 ` [PATCH v11 4/7] x86/kvm/hyper-v: Add support for synthetic debugger capability Jon Doron
2020-05-29 10:46   ` Paolo Bonzini
2020-05-29 12:08     ` Vitaly Kuznetsov
2020-05-29 12:17       ` Paolo Bonzini
2020-04-24 11:37 ` [PATCH v11 5/7] x86/kvm/hyper-v: enable hypercalls without hypercall page with syndbg Jon Doron
2020-05-13  9:57   ` Roman Kagan [this message]
2020-05-13 12:37     ` Jon Doron
2020-05-29 10:48   ` Paolo Bonzini
2020-04-24 11:37 ` [PATCH v11 6/7] x86/kvm/hyper-v: Add support for synthetic debugger via hypercalls Jon Doron
2020-05-12 15:33   ` Roman Kagan
2020-05-13 12:39     ` Jon Doron
2020-04-24 11:37 ` [PATCH v11 7/7] KVM: selftests: update hyperv_cpuid with SynDBG tests Jon Doron
2020-05-07  3:01 ` [PATCH v11 0/7] x86/kvm/hyper-v: add support for synthetic debugger Jon Doron
2020-05-07  7:57   ` 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=20200513095738.GC29650@rvkaganb.lan \
    --to=rvkagan@yandex-team.ru \
    --cc=arilou@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=vkuznets@redhat.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

Linux-HyperV Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-hyperv/0 linux-hyperv/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-hyperv linux-hyperv/ https://lore.kernel.org/linux-hyperv \
		linux-hyperv@vger.kernel.org
	public-inbox-index linux-hyperv

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-hyperv


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git