From patchwork Thu Mar 19 05:58:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Doron X-Patchwork-Id: 11446519 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EC0961392 for ; Thu, 19 Mar 2020 05:59:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CBF8B20740 for ; Thu, 19 Mar 2020 05:59:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nOOB05Ht" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727089AbgCSF7A (ORCPT ); Thu, 19 Mar 2020 01:59:00 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:38976 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725767AbgCSF7A (ORCPT ); Thu, 19 Mar 2020 01:59:00 -0400 Received: by mail-wr1-f66.google.com with SMTP id h6so1166997wrs.6; Wed, 18 Mar 2020 22:58:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qORovMW4qFXFXcdoIljFzjQs+83nq3xI2+7AeVXu0Jo=; b=nOOB05HtYbAQ6YRUSNddR9ZQ+6/ctli+nnZkioh6T3HYsfY4+Zuew9FggRhG2speTc awFaRyQYwhZPzl12+wYCReZL2030hIO/t4NouiMRtPF2zVcZ8XOqe8M6B2oGWHYi43Uq k7Jgw3umWgtcSc8NQJpK4vWdBA+96kHOokL8iwldpbE2epRj57ltRRD5ez8V28OsEg9w bdqAHn2hnj7r90T655m3EWVAPQhKFyfR253k33N86mNty69Ep3JmA42p2dVJXsTQSOO+ k5qeQ3ZMMMZYBlbSzvlz10Qrmpj3h6UcsMLgsScaafKKU9JVA8IhWVvprq4XajLNyLTF h6xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qORovMW4qFXFXcdoIljFzjQs+83nq3xI2+7AeVXu0Jo=; b=bPTPCRGWw9VKfivv3TTQtMWWS6TRe3QkUbefDLY+D4/n/RVQVbNagCcA7TC/jJjN9o xGQupVshIM7sGxL+K/CH/luQijswAQ6ROEbyhY97ciZoN0ChFcnKcKxONLyvE1n3SGaK 4+MZIm5IHl7SAKSq6JqzWdnei+Anza7eI9qpnPveiT86oqwAcXq82/yaOFFJXA27rurR qkiY/m3fLfWyGw/8C7Z7xa6PQqQcubkEOKyGj0cxmK5EeZcUdfTmqLncZo/F8J+SNBEg ZzCoCFlVwAMZnvZPx6cCiau63HIjF2PNt2jvr5JvVbuq34VeR98Lvu/1lk6YLZ1IdkGp 1Y1g== X-Gm-Message-State: ANhLgQ34dM//TqMO9pnKpOG/V1OmXJ2CT1ZwlNF7l/ZOz2ej3ofRFV1y wbFIA6ETDwW9dfZwqRKtzJU+Jv+cQX8= X-Google-Smtp-Source: ADFU+vtnopswMiu3EvNFMbvxn803dFChQpCfrbFVo1x6X+PQHxVbVqXJ4Sybbk9f2hJDEY835gKyoQ== X-Received: by 2002:a5d:69cb:: with SMTP id s11mr1832766wrw.47.1584597537739; Wed, 18 Mar 2020 22:58:57 -0700 (PDT) Received: from jondnuc.lan (IGLD-84-229-155-229.inter.net.il. [84.229.155.229]) by smtp.gmail.com with ESMTPSA id n2sm1884174wro.25.2020.03.18.22.58.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2020 22:58:57 -0700 (PDT) From: Jon Doron To: kvm@vger.kernel.org, linux-hyperv@vger.kernel.org Cc: vkuznets@redhat.com, Jon Doron Subject: [PATCH v7 1/5] x86/kvm/hyper-v: Explicitly align hcall param for kvm_hyperv_exit Date: Thu, 19 Mar 2020 07:58:38 +0200 Message-Id: <20200319055842.673513-2-arilou@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200319055842.673513-1-arilou@gmail.com> References: <20200319055842.673513-1-arilou@gmail.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The problem the patch is trying to address is the fact that 'struct kvm_hyperv_exit' has different layout on when compiling in 32 and 64 bit modes. In 64-bit mode the default alignment boundary is 64 bits thus forcing extra gaps after 'type' and 'msr' but in 32-bit mode the boundary is at 32 bits thus no extra gaps. This is an issue as even when the kernel is 64 bit, the userspace using the interface can be both 32 and 64 bit but the same 32 bit userspace has to work with 32 bit kernel. The issue is fixed by forcing the 64 bit layout, this leads to ABI change for 32 bit builds and while we are obviously breaking '32 bit userspace with 32 bit kernel' case, we're fixing the '32 bit userspace with 64 bit kernel' one. As the interface has no (known) users and 32 bit KVM is rather baroque nowadays, this seems like a reasonable decision. Signed-off-by: Jon Doron --- Documentation/virt/kvm/api.rst | 2 ++ include/uapi/linux/kvm.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index ebd383fba939..4872c47bbcff 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -5025,9 +5025,11 @@ EOI was received. #define KVM_EXIT_HYPERV_SYNIC 1 #define KVM_EXIT_HYPERV_HCALL 2 __u32 type; + __u32 pad1; union { struct { __u32 msr; + __u32 pad2; __u64 control; __u64 evt_page; __u64 msg_page; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 4b95f9a31a2f..7ee0ddc4c457 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -189,9 +189,11 @@ struct kvm_hyperv_exit { #define KVM_EXIT_HYPERV_SYNIC 1 #define KVM_EXIT_HYPERV_HCALL 2 __u32 type; + __u32 pad1; union { struct { __u32 msr; + __u32 pad2; __u64 control; __u64 evt_page; __u64 msg_page; From patchwork Thu Mar 19 05:58:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Doron X-Patchwork-Id: 11446521 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 588861874 for ; Thu, 19 Mar 2020 05:59:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 39A5220732 for ; Thu, 19 Mar 2020 05:59:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="o9x/UL9w" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727196AbgCSF7B (ORCPT ); Thu, 19 Mar 2020 01:59:01 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:33472 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725747AbgCSF7A (ORCPT ); Thu, 19 Mar 2020 01:59:00 -0400 Received: by mail-wr1-f65.google.com with SMTP id a25so1210243wrd.0; Wed, 18 Mar 2020 22:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z3+1+dijIgsDdRQRSO438ZaqORDXumTy12HEHcvkxO4=; b=o9x/UL9w1fDYHIILcFa3uf6aJn216iEFxLANPYEj0KCgjVE0sfK7iXLkR5l4IMezEU pypSxDT/IyLFJcD66Le3K518eBKywXI2vB6GeZ14tl4quN6eZm3Ad/QqCrxyDDC5Gx/2 5nuxHTzBLxpktqmvYxoz7fcHs9WnKHIpXe8gZTe5mJ266gs+OCYFpcBr0D8NFqU3tC3Q QqzYmVsiuowPtYgybd/upeC0mwFzFchOPkUxzsiQwURrNl1Zhzp0iA6fqgZoy2QcU/kq DhGWP2rRQqV7Sw/6xrNKxqY1VUK2BiT9oonjrLHdkfxY/ll+J3cm8OE7RoDoffWEF7i4 aAbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z3+1+dijIgsDdRQRSO438ZaqORDXumTy12HEHcvkxO4=; b=frQB7wmtpmtLY5LVAlOibezgHPJOxrqz1QDibpoaUeyiJ0MN5iNvLd2hynJHmxb9Ab HT9Y/lxFZSZzs0uzpfqO5hEmR1X8qPzdmbj+UDLSGanTJH8UwPoGo5bZK4Kl5Tx54Q/q pxd/Nz1yz706r0s2I9olZNrr8wVVA9Pi7hAq/6CUEd7x/QMBTTt+Vq4P1g4zmAp7UOQ1 Pfb+wXM3oXMjeR4nu6y4dQclEx29RH1PEvKwNzoAeyHYjRKrPVX9vqivRrXd5jaCypv3 CBOC+uE5wlfc5iVoESRmC99BTSqhmkBLeTdMzKFqGz8EzTZeA5foKYGJvVUIfRr7H8/y 7FxA== X-Gm-Message-State: ANhLgQ1zcRPJ8sGwmnR3xFcd7YbgfuX5sHDWrQi/Zze4HNKBrvNEOv0o tg1h4SKwIHczBY6USSx8xHNK2rKhEG8= X-Google-Smtp-Source: ADFU+vsLposVLHjCC8lWMItUmuIh5NIV6j4I3k82zdQhTS/E0QY6utF4w7JXAha/lHglDeegb188jg== X-Received: by 2002:adf:fe03:: with SMTP id n3mr434293wrr.266.1584597538952; Wed, 18 Mar 2020 22:58:58 -0700 (PDT) Received: from jondnuc.lan (IGLD-84-229-155-229.inter.net.il. [84.229.155.229]) by smtp.gmail.com with ESMTPSA id n2sm1884174wro.25.2020.03.18.22.58.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2020 22:58:58 -0700 (PDT) From: Jon Doron To: kvm@vger.kernel.org, linux-hyperv@vger.kernel.org Cc: vkuznets@redhat.com, Jon Doron Subject: [PATCH v7 2/5] x86/hyper-v: Add synthetic debugger definitions Date: Thu, 19 Mar 2020 07:58:39 +0200 Message-Id: <20200319055842.673513-3-arilou@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200319055842.673513-1-arilou@gmail.com> References: <20200319055842.673513-1-arilou@gmail.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Hyper-V synthetic debugger has two modes, one that uses MSRs and the other that use Hypercalls. Add all the required definitions to both types of synthetic debugger interface. Some of the required new CPUIDs and MSRs are not documented in the TLFS so they are in hyperv.h instead. The reason they are not documented is because they are subjected to be removed in future versions of Windows. Signed-off-by: Jon Doron --- arch/x86/include/asm/hyperv-tlfs.h | 6 ++++++ arch/x86/kvm/hyperv.h | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index 92abc1e42bfc..671ce2a39d4b 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -131,6 +131,8 @@ #define HV_FEATURE_FREQUENCY_MSRS_AVAILABLE BIT(8) /* Crash MSR available */ #define HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE BIT(10) +/* Support for debug MSRs available */ +#define HV_FEATURE_DEBUG_MSRS_AVAILABLE BIT(11) /* stimer Direct Mode is available */ #define HV_STIMER_DIRECT_MODE_AVAILABLE BIT(19) @@ -376,6 +378,9 @@ struct hv_tsc_emulation_status { #define HVCALL_SEND_IPI_EX 0x0015 #define HVCALL_POST_MESSAGE 0x005c #define HVCALL_SIGNAL_EVENT 0x005d +#define HVCALL_POST_DEBUG_DATA 0x0069 +#define HVCALL_RETRIEVE_DEBUG_DATA 0x006a +#define HVCALL_RESET_DEBUG_SESSION 0x006b #define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af #define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0 @@ -419,6 +424,7 @@ enum HV_GENERIC_SET_FORMAT { #define HV_STATUS_INVALID_HYPERCALL_INPUT 3 #define HV_STATUS_INVALID_ALIGNMENT 4 #define HV_STATUS_INVALID_PARAMETER 5 +#define HV_STATUS_OPERATION_DENIED 8 #define HV_STATUS_INSUFFICIENT_MEMORY 11 #define HV_STATUS_INVALID_PORT_ID 17 #define HV_STATUS_INVALID_CONNECTION_ID 18 diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h index 757cb578101c..5e4780bf6dd7 100644 --- a/arch/x86/kvm/hyperv.h +++ b/arch/x86/kvm/hyperv.h @@ -23,6 +23,33 @@ #include +/* + * The #defines related to the synthetic debugger are required by KDNet, but + * they are not documented in the Hyper-V TLFS because the synthetic debugger + * functionality has been deprecated and is subject to removal in future versions + * of Windows. + */ +#define HYPERV_CPUID_SYNDBG_VENDOR_AND_MAX_FUNCTIONS 0x40000080 +#define HYPERV_CPUID_SYNDBG_INTERFACE 0x40000081 +#define HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES 0x40000082 + +/* + * Hyper-V synthetic debugger platform capabilities + * These are HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES.EAX bits. + */ +#define HV_X64_SYNDBG_CAP_ALLOW_KERNEL_DEBUGGING BIT(1) + +/* Hyper-V Synthetic debug options MSR */ +#define HV_X64_MSR_SYNDBG_CONTROL 0x400000F1 +#define HV_X64_MSR_SYNDBG_STATUS 0x400000F2 +#define HV_X64_MSR_SYNDBG_SEND_BUFFER 0x400000F3 +#define HV_X64_MSR_SYNDBG_RECV_BUFFER 0x400000F4 +#define HV_X64_MSR_SYNDBG_PENDING_BUFFER 0x400000F5 +#define HV_X64_MSR_SYNDBG_OPTIONS 0x400000FF + +/* Hyper-V HV_X64_MSR_SYNDBG_OPTIONS bits */ +#define HV_X64_SYNDBG_OPTION_USE_HCALLS BIT(2) + static inline struct kvm_vcpu_hv *vcpu_to_hv_vcpu(struct kvm_vcpu *vcpu) { return &vcpu->arch.hyperv; From patchwork Thu Mar 19 05:58:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Doron X-Patchwork-Id: 11446527 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 243A31874 for ; Thu, 19 Mar 2020 05:59:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DAC6A20740 for ; Thu, 19 Mar 2020 05:59:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mfIg3KQp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727198AbgCSF7G (ORCPT ); Thu, 19 Mar 2020 01:59:06 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:35572 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726589AbgCSF7F (ORCPT ); Thu, 19 Mar 2020 01:59:05 -0400 Received: by mail-wm1-f65.google.com with SMTP id m3so650975wmi.0; Wed, 18 Mar 2020 22:59:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l104BDudzxcjq4iugSLSZXbmdkV2sUZbwNH9jdDEMwM=; b=mfIg3KQpRciJc4vvcKHYgl32bEmlOnjiDr4ZYQzsw+4c2v8JaKLWK9VGpz2VXf+j3h uaKsWFuRn4fmfA8v+1Yi2wwzV3DYMTikrts2UsvS3HTWkLGG/mx1dbdmZJ0KZLXgS4QN s4Tsayfja0+/eLDBz9hpTLNK0EtPQMWd905h9ixScx+LpFjL2P7MdeG0H8Woyx9HS+t6 Wp9gWKLzgZWG+dLNbl2h8ZaIzPFZEpwaIEhi1r3aBK+1uILk13tSnta1qgdKtC4x6M1B FoTidsawFLTpuu/iGgS7wXkTt5AjntIHL8YpLviMpv+Fc8jYcjPK78LEs/TycteEA17z AsIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=l104BDudzxcjq4iugSLSZXbmdkV2sUZbwNH9jdDEMwM=; b=PaslS665tTjGTlhazTrcx/jVaHn772K63pVUSN0oYhbePJ1EUnR6fD+HK5a9M0y6pc frgZNRpL3bCd9mJDdaRhj2ed/iWFiTpLDUOcsjvy4i/9tqn+aBxvIr4eu+9qGR6JwLOr 2GD4XKt23ScpYdPWnTTD6lJaD8ivZjSe0evlXE2UkjkHGfLUCEliqsq2jQp1QpKGNwgL mDk34ZGBXLHq3Ci+QfT42ae71Qqeef59eKm8O2xBWfGMHzkrH6KKXtmZ+/fI4/M7zmpS TrkGwuq/f2f/kq+Bo9cL8Q6LYofKdmaGK4cxu8y6HECIoLieaiHuHOEn9cxVijedi57B Geew== X-Gm-Message-State: ANhLgQ08xbVpKQLZzpSXRFRTAqykoCl6aQ1Tze3DMvpZhJqov854S607 K24016xFtAQ0g4TyP8XnxAJFWsLCbFk= X-Google-Smtp-Source: ADFU+vtNZBHIN1YL7FyT9FdA7+1PcYaZKUAA5u5NtHvyS/vj+zczEl4KAkysONp9MtfvgWVhW034ow== X-Received: by 2002:a1c:7ec9:: with SMTP id z192mr1604921wmc.100.1584597539989; Wed, 18 Mar 2020 22:58:59 -0700 (PDT) Received: from jondnuc.lan (IGLD-84-229-155-229.inter.net.il. [84.229.155.229]) by smtp.gmail.com with ESMTPSA id n2sm1884174wro.25.2020.03.18.22.58.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2020 22:58:59 -0700 (PDT) From: Jon Doron To: kvm@vger.kernel.org, linux-hyperv@vger.kernel.org Cc: vkuznets@redhat.com, Jon Doron Subject: [PATCH v7 3/5] x86/kvm/hyper-v: Add support for synthetic debugger capability Date: Thu, 19 Mar 2020 07:58:40 +0200 Message-Id: <20200319055842.673513-4-arilou@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200319055842.673513-1-arilou@gmail.com> References: <20200319055842.673513-1-arilou@gmail.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add support for Hyper-V synthetic debugger (syndbg) interface. The syndbg interface is using MSRs to emulate a way to send/recv packets data. The debug transport dll (kdvm/kdnet) will identify if Hyper-V is enabled and if it supports the synthetic debugger interface it will attempt to use it, instead of trying to initialize a network adapter. Signed-off-by: Jon Doron --- Documentation/virt/kvm/api.rst | 16 ++++ arch/x86/include/asm/kvm_host.h | 14 ++++ arch/x86/kvm/hyperv.c | 144 +++++++++++++++++++++++++++++++- arch/x86/kvm/hyperv.h | 6 ++ arch/x86/kvm/trace.h | 51 +++++++++++ arch/x86/kvm/x86.c | 13 +++ include/uapi/linux/kvm.h | 11 +++ 7 files changed, 254 insertions(+), 1 deletion(-) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index 4872c47bbcff..fe992dcf4f93 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -5024,6 +5024,7 @@ EOI was received. struct kvm_hyperv_exit { #define KVM_EXIT_HYPERV_SYNIC 1 #define KVM_EXIT_HYPERV_HCALL 2 + #define KVM_EXIT_HYPERV_SYNDBG 3 __u32 type; __u32 pad1; union { @@ -5039,6 +5040,15 @@ EOI was received. __u64 result; __u64 params[2]; } hcall; + struct { + __u32 msr; + __u32 pad2; + __u64 control; + __u64 status; + __u64 send_page; + __u64 recv_page; + __u64 pending_page; + } syndbg; } u; }; /* KVM_EXIT_HYPERV */ @@ -5055,6 +5065,12 @@ 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_SYNDBG -- synchronously notify user-space about + +Hyper-V Synthetic debugger state change. Notification is used to either update +the pending_page location or to send a control command (send the buffer located +in send_page or recv a buffer to recv_page). + :: /* KVM_EXIT_ARM_NISV */ diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 98959e8cd448..c09fa7401b13 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -854,6 +854,19 @@ struct kvm_apic_map { struct kvm_lapic *phys_map[]; }; +/* Hyper-V synthetic debugger (SynDbg)*/ +struct kvm_hv_syndbg { + struct { + u64 control; + u64 status; + u64 send_page; + u64 recv_page; + u64 pending_page; + } control; + u64 options; + bool active; +}; + /* Hyper-V emulation context */ struct kvm_hv { struct mutex hv_lock; @@ -877,6 +890,7 @@ struct kvm_hv { atomic_t num_mismatched_vp_indexes; struct hv_partition_assist_pg *hv_pa_pg; + struct kvm_hv_syndbg hv_syndbg; }; enum kvm_irqchip_mode { diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index a86fda7a1d03..4c482ef1eaa9 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -266,6 +266,111 @@ static int synic_set_msr(struct kvm_vcpu_hv_synic *synic, return ret; } +void kvm_hv_activate_syndbg(struct kvm_vcpu *vcpu) +{ + struct kvm_hv_syndbg *syndbg = vcpu_to_hv_syndbg(vcpu); + + syndbg->active = true; +} + +static int kvm_hv_syndbg_complete_userspace(struct kvm_vcpu *vcpu) +{ + struct kvm *kvm = vcpu->kvm; + struct kvm_hv *hv = &kvm->arch.hyperv; + + if (vcpu->run->hyperv.u.syndbg.msr == HV_X64_MSR_SYNDBG_CONTROL) + hv->hv_syndbg.control.status = + vcpu->run->hyperv.u.syndbg.status; + return 1; +} + +static void syndbg_exit(struct kvm_vcpu *vcpu, u32 msr) +{ + struct kvm_hv_syndbg *syndbg = vcpu_to_hv_syndbg(vcpu); + struct kvm_vcpu_hv *hv_vcpu = &vcpu->arch.hyperv; + + hv_vcpu->exit.type = KVM_EXIT_HYPERV_SYNDBG; + hv_vcpu->exit.u.syndbg.msr = msr; + hv_vcpu->exit.u.syndbg.control = syndbg->control.control; + hv_vcpu->exit.u.syndbg.send_page = syndbg->control.send_page; + hv_vcpu->exit.u.syndbg.recv_page = syndbg->control.recv_page; + hv_vcpu->exit.u.syndbg.pending_page = syndbg->control.pending_page; + vcpu->arch.complete_userspace_io = + kvm_hv_syndbg_complete_userspace; + + kvm_make_request(KVM_REQ_HV_EXIT, vcpu); +} + +static void syndbg_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data) +{ + struct kvm_hv_syndbg *syndbg = vcpu_to_hv_syndbg(vcpu); + + if (!syndbg->active) + return; + + trace_kvm_hv_syndbg_set_msr(vcpu->vcpu_id, + vcpu_to_hv_vcpu(vcpu)->vp_index, msr, data); + switch (msr) { + case HV_X64_MSR_SYNDBG_CONTROL: + syndbg->control.control = data; + syndbg_exit(vcpu, msr); + break; + case HV_X64_MSR_SYNDBG_STATUS: + syndbg->control.status = data; + break; + case HV_X64_MSR_SYNDBG_SEND_BUFFER: + syndbg->control.send_page = data; + break; + case HV_X64_MSR_SYNDBG_RECV_BUFFER: + syndbg->control.recv_page = data; + break; + case HV_X64_MSR_SYNDBG_PENDING_BUFFER: + syndbg->control.pending_page = data; + syndbg_exit(vcpu, msr); + break; + case HV_X64_MSR_SYNDBG_OPTIONS: + syndbg->options = data; + break; + default: + break; + } +} + +static void syndbg_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) +{ + struct kvm_hv_syndbg *syndbg = vcpu_to_hv_syndbg(vcpu); + + if (!syndbg->active) + return; + + switch (msr) { + case HV_X64_MSR_SYNDBG_CONTROL: + *pdata = syndbg->control.control; + break; + case HV_X64_MSR_SYNDBG_STATUS: + *pdata = syndbg->control.status; + break; + case HV_X64_MSR_SYNDBG_SEND_BUFFER: + *pdata = syndbg->control.send_page; + break; + case HV_X64_MSR_SYNDBG_RECV_BUFFER: + *pdata = syndbg->control.recv_page; + break; + case HV_X64_MSR_SYNDBG_PENDING_BUFFER: + *pdata = syndbg->control.pending_page; + break; + case HV_X64_MSR_SYNDBG_OPTIONS: + *pdata = syndbg->options; + break; + default: + break; + } + + trace_kvm_hv_syndbg_get_msr(vcpu->vcpu_id, + vcpu_to_hv_vcpu(vcpu)->vp_index, msr, + *pdata); +} + static int synic_get_msr(struct kvm_vcpu_hv_synic *synic, u32 msr, u64 *pdata, bool host) { @@ -800,6 +905,8 @@ static bool kvm_hv_msr_partition_wide(u32 msr) case HV_X64_MSR_REENLIGHTENMENT_CONTROL: case HV_X64_MSR_TSC_EMULATION_CONTROL: case HV_X64_MSR_TSC_EMULATION_STATUS: + case HV_X64_MSR_SYNDBG_OPTIONS: + case HV_X64_MSR_SYNDBG_CONTROL ... HV_X64_MSR_SYNDBG_PENDING_BUFFER: r = true; break; } @@ -1061,6 +1168,10 @@ static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data, if (!host) return 1; break; + case HV_X64_MSR_SYNDBG_OPTIONS: + case HV_X64_MSR_SYNDBG_CONTROL ... HV_X64_MSR_SYNDBG_PENDING_BUFFER: + syndbg_set_msr(vcpu, msr, data); + break; default: vcpu_unimpl(vcpu, "Hyper-V unhandled wrmsr: 0x%x data 0x%llx\n", msr, data); @@ -1227,6 +1338,10 @@ static int kvm_hv_get_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) case HV_X64_MSR_TSC_EMULATION_STATUS: data = hv->hv_tsc_emulation_status; break; + case HV_X64_MSR_SYNDBG_OPTIONS: + case HV_X64_MSR_SYNDBG_CONTROL ... HV_X64_MSR_SYNDBG_PENDING_BUFFER: + syndbg_get_msr(vcpu, msr, pdata); + break; default: vcpu_unimpl(vcpu, "Hyper-V unhandled rdmsr: 0x%x\n", msr); return 1; @@ -1797,8 +1912,12 @@ int kvm_vcpu_ioctl_get_hv_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid, { .function = HYPERV_CPUID_ENLIGHTMENT_INFO }, { .function = HYPERV_CPUID_IMPLEMENT_LIMITS }, { .function = HYPERV_CPUID_NESTED_FEATURES }, + { .function = HYPERV_CPUID_SYNDBG_VENDOR_AND_MAX_FUNCTIONS }, + { .function = HYPERV_CPUID_SYNDBG_INTERFACE }, + { .function = HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES }, }; int i, nent = ARRAY_SIZE(cpuid_entries); + struct kvm_hv_syndbg *syndbg = vcpu_to_hv_syndbg(vcpu); if (kvm_x86_ops->nested_get_evmcs_version) evmcs_ver = kvm_x86_ops->nested_get_evmcs_version(vcpu); @@ -1821,7 +1940,9 @@ int kvm_vcpu_ioctl_get_hv_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid, case HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS: memcpy(signature, "Linux KVM Hv", 12); - ent->eax = HYPERV_CPUID_NESTED_FEATURES; + ent->eax = syndbg->active ? + HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES : + HYPERV_CPUID_NESTED_FEATURES; ent->ebx = signature[0]; ent->ecx = signature[1]; ent->edx = signature[2]; @@ -1856,9 +1977,12 @@ int kvm_vcpu_ioctl_get_hv_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid, ent->ebx |= HV_X64_POST_MESSAGES; ent->ebx |= HV_X64_SIGNAL_EVENTS; + ent->ebx |= HV_X64_DEBUGGING; ent->edx |= HV_FEATURE_FREQUENCY_MSRS_AVAILABLE; ent->edx |= HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE; + ent->edx |= HV_X64_GUEST_DEBUGGING_AVAILABLE; + ent->edx |= HV_FEATURE_DEBUG_MSRS_AVAILABLE; /* * Direct Synthetic timers only make sense with in-kernel @@ -1903,6 +2027,24 @@ int kvm_vcpu_ioctl_get_hv_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid, break; + case HYPERV_CPUID_SYNDBG_VENDOR_AND_MAX_FUNCTIONS: + memcpy(signature, "Linux KVM Hv", 12); + + ent->eax = 0; + ent->ebx = signature[0]; + ent->ecx = signature[1]; + ent->edx = signature[2]; + break; + + case HYPERV_CPUID_SYNDBG_INTERFACE: + memcpy(signature, "VS#1\0\0\0\0\0\0\0\0", 12); + ent->eax = signature[0]; + break; + + case HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES: + ent->eax |= HV_X64_SYNDBG_CAP_ALLOW_KERNEL_DEBUGGING; + break; + default: break; } diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h index 5e4780bf6dd7..45aaaf08bf15 100644 --- a/arch/x86/kvm/hyperv.h +++ b/arch/x86/kvm/hyperv.h @@ -73,6 +73,11 @@ static inline struct kvm_vcpu *synic_to_vcpu(struct kvm_vcpu_hv_synic *synic) return hv_vcpu_to_vcpu(container_of(synic, struct kvm_vcpu_hv, synic)); } +static inline struct kvm_hv_syndbg *vcpu_to_hv_syndbg(struct kvm_vcpu *vcpu) +{ + return &vcpu->kvm->arch.hyperv.hv_syndbg; +} + int kvm_hv_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host); int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata, bool host); @@ -83,6 +88,7 @@ void kvm_hv_irq_routing_update(struct kvm *kvm); int kvm_hv_synic_set_irq(struct kvm *kvm, u32 vcpu_id, u32 sint); void kvm_hv_synic_send_eoi(struct kvm_vcpu *vcpu, int vector); int kvm_hv_activate_synic(struct kvm_vcpu *vcpu, bool dont_zero_synic_pages); +void kvm_hv_activate_syndbg(struct kvm_vcpu *vcpu); void kvm_hv_vcpu_init(struct kvm_vcpu *vcpu); void kvm_hv_vcpu_postcreate(struct kvm_vcpu *vcpu); diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h index f194dd058470..bf6c3852868d 100644 --- a/arch/x86/kvm/trace.h +++ b/arch/x86/kvm/trace.h @@ -1515,6 +1515,57 @@ TRACE_EVENT(kvm_nested_vmenter_failed, __print_symbolic(__entry->err, VMX_VMENTER_INSTRUCTION_ERRORS)) ); +/* + * Tracepoint for syndbg_set_msr. + */ +TRACE_EVENT(kvm_hv_syndbg_set_msr, + TP_PROTO(int vcpu_id, u32 vp_index, u32 msr, u64 data), + TP_ARGS(vcpu_id, vp_index, msr, data), + + TP_STRUCT__entry( + __field(int, vcpu_id) + __field(u32, vp_index) + __field(u32, msr) + __field(u64, data) + ), + + TP_fast_assign( + __entry->vcpu_id = vcpu_id; + __entry->vp_index = vp_index; + __entry->msr = msr; + __entry->data = data; + ), + + TP_printk("vcpu_id %d vp_index %u msr 0x%x data 0x%llx", + __entry->vcpu_id, __entry->vp_index, __entry->msr, + __entry->data) +); + +/* + * Tracepoint for syndbg_get_msr. + */ +TRACE_EVENT(kvm_hv_syndbg_get_msr, + TP_PROTO(int vcpu_id, u32 vp_index, u32 msr, u64 data), + TP_ARGS(vcpu_id, vp_index, msr, data), + + TP_STRUCT__entry( + __field(int, vcpu_id) + __field(u32, vp_index) + __field(u32, msr) + __field(u64, data) + ), + + TP_fast_assign( + __entry->vcpu_id = vcpu_id; + __entry->vp_index = vp_index; + __entry->msr = msr; + __entry->data = data; + ), + + TP_printk("vcpu_id %d vp_index %u msr 0x%x data 0x%llx", + __entry->vcpu_id, __entry->vp_index, __entry->msr, + __entry->data) +); #endif /* _TRACE_KVM_H */ #undef TRACE_INCLUDE_PATH diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3156e25b0774..7bfa30d7a525 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1214,6 +1214,10 @@ static const u32 emulated_msrs_all[] = { HV_X64_MSR_VP_ASSIST_PAGE, HV_X64_MSR_REENLIGHTENMENT_CONTROL, HV_X64_MSR_TSC_EMULATION_CONTROL, HV_X64_MSR_TSC_EMULATION_STATUS, + HV_X64_MSR_SYNDBG_OPTIONS, + HV_X64_MSR_SYNDBG_CONTROL, HV_X64_MSR_SYNDBG_STATUS, + HV_X64_MSR_SYNDBG_SEND_BUFFER, HV_X64_MSR_SYNDBG_RECV_BUFFER, + HV_X64_MSR_SYNDBG_PENDING_BUFFER, MSR_KVM_ASYNC_PF_EN, MSR_KVM_STEAL_TIME, MSR_KVM_PV_EOI_EN, @@ -2906,6 +2910,8 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) */ break; case HV_X64_MSR_GUEST_OS_ID ... HV_X64_MSR_SINT15: + case HV_X64_MSR_SYNDBG_CONTROL ... HV_X64_MSR_SYNDBG_PENDING_BUFFER: + case HV_X64_MSR_SYNDBG_OPTIONS: case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4: case HV_X64_MSR_CRASH_CTL: case HV_X64_MSR_STIMER0_CONFIG ... HV_X64_MSR_STIMER3_COUNT: @@ -3151,6 +3157,8 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) msr_info->data = 0x20000000; break; case HV_X64_MSR_GUEST_OS_ID ... HV_X64_MSR_SINT15: + case HV_X64_MSR_SYNDBG_CONTROL ... HV_X64_MSR_SYNDBG_PENDING_BUFFER: + case HV_X64_MSR_SYNDBG_OPTIONS: case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4: case HV_X64_MSR_CRASH_CTL: case HV_X64_MSR_STIMER0_CONFIG ... HV_X64_MSR_STIMER3_COUNT: @@ -3323,6 +3331,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) case KVM_CAP_HYPERV_TLBFLUSH: case KVM_CAP_HYPERV_SEND_IPI: case KVM_CAP_HYPERV_CPUID: + case KVM_CAP_HYPERV_SYNDBG: case KVM_CAP_PCI_SEGMENT: case KVM_CAP_DEBUGREGS: case KVM_CAP_X86_ROBUST_SINGLESTEP: @@ -4178,6 +4187,10 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu, return -EINVAL; switch (cap->cap) { + case KVM_CAP_HYPERV_SYNDBG: + kvm_hv_activate_syndbg(vcpu); + return 0; + case KVM_CAP_HYPERV_SYNIC2: if (cap->args[0]) return -EINVAL; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 7ee0ddc4c457..0b573e1155c8 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -188,6 +188,7 @@ struct kvm_s390_cmma_log { struct kvm_hyperv_exit { #define KVM_EXIT_HYPERV_SYNIC 1 #define KVM_EXIT_HYPERV_HCALL 2 +#define KVM_EXIT_HYPERV_SYNDBG 3 __u32 type; __u32 pad1; union { @@ -203,6 +204,15 @@ struct kvm_hyperv_exit { __u64 result; __u64 params[2]; } hcall; + struct { + __u32 msr; + __u32 pad2; + __u64 control; + __u64 status; + __u64 send_page; + __u64 recv_page; + __u64 pending_page; + } syndbg; } u; }; @@ -1012,6 +1022,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_ARM_NISV_TO_USER 177 #define KVM_CAP_ARM_INJECT_EXT_DABT 178 #define KVM_CAP_S390_VCPU_RESETS 179 +#define KVM_CAP_HYPERV_SYNDBG 180 #ifdef KVM_CAP_IRQ_ROUTING From patchwork Thu Mar 19 05:58:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Doron X-Patchwork-Id: 11446523 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 163A91874 for ; Thu, 19 Mar 2020 05:59:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EA3C220732 for ; Thu, 19 Mar 2020 05:59:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QkixoLXV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727222AbgCSF7D (ORCPT ); Thu, 19 Mar 2020 01:59:03 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:38982 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725747AbgCSF7D (ORCPT ); Thu, 19 Mar 2020 01:59:03 -0400 Received: by mail-wr1-f68.google.com with SMTP id h6so1167086wrs.6; Wed, 18 Mar 2020 22:59:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lnqp5rPGccrlR5PSxxdbXEbVJk1qCq/tIZPYxPoQFaw=; b=QkixoLXVD0UcK6cHusQduB2Kr0e+6dj0L1jwQEMYOZOk/5YTs1y+GlcwgVk/BeHWuR jkOvl9dW/B5vJVECjDbH6w6vd+IcC6wOM54S3BiSAsuijov7RAtrEgseIaXHxJlR9SRm OfY4qCoo1BMtUU7it7+1WCROITD9ZCmI4qmSGdY6Pb08gSzH0IP95aS62u8zvDiOlGdl 6dkI9yk3C14vrmBRrnW0d8zgMBvwkt0KOrnR3bZFAJsBDCt25OeeveIMP/yhhf3F4jHG VvFdfENTwPzioMGAL1+OnlxT9bxtmKsv7uucIzVImi+6879DOenyaIwFojyqr8v0oZ55 rLqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lnqp5rPGccrlR5PSxxdbXEbVJk1qCq/tIZPYxPoQFaw=; b=NCbmF0+L0UFU73joATvxF5F4tp697p3/yiV20rVJIBYULLF+w3/U7Yyyg2FA11dx0U RauVOO71njDdi9KptoZXOj4u6k9KXdeWPNMRfPTznSQRH/dUTMe/ecar+yhK/XXRaNyz bDHp2uiB/T0OW7p23/wVui9JWztpbwZFvoBfj4hP1CX5F8TgSzViQHQ9Q3nXKFZ1Zfxv Rl0110gNwlcCMs49uR0aD9XrtFn+Z7wqh5a5BgSEyRhGMkkh8OhhSk5xb8EioG7eF1tp DFzu9JmQt0R0A1azfc5hwhVbWXvviZA2Z0/QttVzBNruHjkbwn+DKUipMJ38vzfGiZ7e loGw== X-Gm-Message-State: ANhLgQ1kwBIGND/06DIedBbAQA6nvlxqlEpl5zofno5wrU1NgxdLpGHL Oet5Q2gnW5k6jI7DRrSxhosDipvFT54= X-Google-Smtp-Source: ADFU+vt32F//3GDlUndDY8MtW6EXhKuqRpbE9vQr2PjpEmuvsGQ5qEDhgQxefmkCM9LOE+xEVJEIVg== X-Received: by 2002:adf:f2c9:: with SMTP id d9mr2004786wrp.12.1584597540966; Wed, 18 Mar 2020 22:59:00 -0700 (PDT) Received: from jondnuc.lan (IGLD-84-229-155-229.inter.net.il. [84.229.155.229]) by smtp.gmail.com with ESMTPSA id n2sm1884174wro.25.2020.03.18.22.59.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2020 22:59:00 -0700 (PDT) From: Jon Doron To: kvm@vger.kernel.org, linux-hyperv@vger.kernel.org Cc: vkuznets@redhat.com, Jon Doron Subject: [PATCH v7 4/5] x86/kvm/hyper-v: enable hypercalls without hypercall page with syndbg Date: Thu, 19 Mar 2020 07:58:41 +0200 Message-Id: <20200319055842.673513-5-arilou@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200319055842.673513-1-arilou@gmail.com> References: <20200319055842.673513-1-arilou@gmail.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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. To resolve this issue simply enable hypercalls also if the guest_os_id is not 0 and the syndbg feature is enabled. Signed-off-by: Jon Doron --- 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 4c482ef1eaa9..67f9893150c3 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -1645,7 +1645,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); } static void kvm_hv_hypercall_set_result(struct kvm_vcpu *vcpu, u64 result) From patchwork Thu Mar 19 05:58:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Doron X-Patchwork-Id: 11446525 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 800001392 for ; Thu, 19 Mar 2020 05:59:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 60A2520740 for ; Thu, 19 Mar 2020 05:59:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pqNWIUdm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727225AbgCSF7E (ORCPT ); Thu, 19 Mar 2020 01:59:04 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:38196 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727148AbgCSF7E (ORCPT ); Thu, 19 Mar 2020 01:59:04 -0400 Received: by mail-wm1-f68.google.com with SMTP id l20so639630wmi.3; Wed, 18 Mar 2020 22:59:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+UwRA0A0GjwbulQIly7HU3QJrvwc4z7tFYKRIMXfkEE=; b=pqNWIUdmljZLUEXle2UXc3DPl4yvWsO0198cZXDN3nA3FOzZTEQQg9tWMZ4Y69fBS1 dZja+H/1DsLW8m+tni3OzSSdQ2dGOchd9qVbldgciq85sX7FTsK7sd03z/lZAapd4PgV evsoubcVe5ZvwUwEl+R7XbLxv1hkohJLt8TLFSnY4828sBhBSAvpo59T+35kjLiEN1D7 mRb3CWXIXe10mn7IQ2XH7LEmJb2LdYTo+J0Eqh2kq+xxfxNjVP5fhKiE61eut66j1tKM rOOkWV58kF0QmZBLP5vYIHKah+QB+UaV/Gcjs6nxyzpbroh25AmySQDqTGCE93slbLTL u8gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+UwRA0A0GjwbulQIly7HU3QJrvwc4z7tFYKRIMXfkEE=; b=DWsLo9eTuqV9cdj/LDv3MuC8WeSAdkOUuYfTyyJOqEyjllCZlQgVRl9ZGpPo4uPkR2 ySc8QldWiDqBX6I6Pkpuzd/qJSysi0TDK21II8erMOm3oP4QlZ++xBaqCgkRcPQEoAeW 4Y1H77lz5RDHbgplfihp0YQhDFUgZ5ufcmeWw43FMxK3QkqX3VH1tdBkKFnsraY1qrhf 44pB+/LNLAQB8Q72vVXVhUO+vhm29FSrYg0gWmJA6x75Lm8xuK1XI8PLS4p85zfhOQ/q /XlvTqFX7qgmX+qTbzU6Tq8OduDnBpyC9QECtutj5JiC9FiFuzqk8f/deBsG4frHeSS/ HcCA== X-Gm-Message-State: ANhLgQ300gt6pRMNkOWZqs/ZlKVE6SMVYY8PFEOimYOwzR4eG5JvBO8L PkwLtZaWXEcvkN1DiFlkWKT/MOTFSjY= X-Google-Smtp-Source: ADFU+vsMrF6LFXzcVt7ZSe3OO8Z+mrvnlumfyNbqN7y5Z6EABurZVADRCEufaI9ZRJmI3bkDtwC75Q== X-Received: by 2002:a7b:c305:: with SMTP id k5mr1632966wmj.189.1584597541944; Wed, 18 Mar 2020 22:59:01 -0700 (PDT) Received: from jondnuc.lan (IGLD-84-229-155-229.inter.net.il. [84.229.155.229]) by smtp.gmail.com with ESMTPSA id n2sm1884174wro.25.2020.03.18.22.59.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2020 22:59:01 -0700 (PDT) From: Jon Doron To: kvm@vger.kernel.org, linux-hyperv@vger.kernel.org Cc: vkuznets@redhat.com, Jon Doron Subject: [PATCH v7 5/5] x86/kvm/hyper-v: Add support for synthetic debugger via hypercalls Date: Thu, 19 Mar 2020 07:58:42 +0200 Message-Id: <20200319055842.673513-6-arilou@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200319055842.673513-1-arilou@gmail.com> References: <20200319055842.673513-1-arilou@gmail.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org There is another mode for the synthetic debugger which uses hypercalls to send/recv network data instead of the MSR interface. This interface is much slower and less recommended since you might get a lot of VMExits while KDVM polling for new packets to recv, rather than simply checking the pending page to see if there is data avialble and then request. Signed-off-by: Jon Doron --- arch/x86/kvm/hyperv.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index 67f9893150c3..a62a330ed322 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -1827,6 +1827,34 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) } ret = kvm_hv_send_ipi(vcpu, ingpa, outgpa, true, false); break; + case HVCALL_POST_DEBUG_DATA: + case HVCALL_RETRIEVE_DEBUG_DATA: + if (unlikely(fast)) { + ret = HV_STATUS_INVALID_PARAMETER; + break; + } + fallthrough; + case HVCALL_RESET_DEBUG_SESSION: { + struct kvm_hv_syndbg *syndbg = vcpu_to_hv_syndbg(vcpu); + + if (!syndbg->active) { + ret = HV_STATUS_INVALID_HYPERCALL_CODE; + break; + } + + if (!(syndbg->options & HV_X64_SYNDBG_OPTION_USE_HCALLS)) { + 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 = param; + vcpu->run->hyperv.u.hcall.params[0] = ingpa; + vcpu->run->hyperv.u.hcall.params[1] = outgpa; + vcpu->arch.complete_userspace_io = + kvm_hv_hypercall_complete_userspace; + return 0; + } default: ret = HV_STATUS_INVALID_HYPERCALL_CODE; break;