From patchwork Sun Dec 29 18:33:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11312357 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 BA6FE921 for ; Sun, 29 Dec 2019 18:35:10 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8FD1520748 for ; Sun, 29 Dec 2019 18:35:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jzmrxNyK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8FD1520748 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ildO6-0008No-4d; Sun, 29 Dec 2019 18:34:02 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ildO5-0008Ne-41 for xen-devel@lists.xenproject.org; Sun, 29 Dec 2019 18:34:01 +0000 X-Inumbo-ID: c5358e60-2a69-11ea-a914-bc764e2007e4 Received: from mail-wm1-x331.google.com (unknown [2a00:1450:4864:20::331]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c5358e60-2a69-11ea-a914-bc764e2007e4; Sun, 29 Dec 2019 18:33:56 +0000 (UTC) Received: by mail-wm1-x331.google.com with SMTP id 20so12569928wmj.4 for ; Sun, 29 Dec 2019 10:33:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Lzk7QT42x4Bu7yTXlGHeGQsXy2o8S3NY1hIpuuMaZPg=; b=jzmrxNyKaQHHXZ7zCuNwtQhbfZZGjTRm2EojYXvM+qcoB+nBkzn5gEWIol77zJ/4gl hRXZnqwVYCkLWg9j2cyYTAp9Zf2UTVN61Rwsu4u45uvUvT3m1wiu4gB7epwC/xo7s6f7 cq+wv5GnLVt1avr62Zx1Ywuyq0auGOEQKWwF3yFR8pwFQzKI5voOxsgp8c2Uqh8+kabs 2R0Pr78L/+0k13w4AbWENQW2apTT5S4/XbTMihHXDf7Vz1aDXUkkmhjSQmNzBbEw72Gn PAnbcRuePpaER21rP9tIj7LbLCsxwt7a9RDB4UkWpA7+ehE9ToKmw2qluUo1uFuS4GXw XfVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Lzk7QT42x4Bu7yTXlGHeGQsXy2o8S3NY1hIpuuMaZPg=; b=qiXyY5twMj+OMvueAW49LzX/Kaj4Qx6Fx3uubvACY2eo4inhyFD9gk6yX37qAUs7sq Ur9JmFENsElXVAdzTfEa+KN4PlUktft037a6X9DaWy1l6XU2znPWPm5PMD/mA5jAjblX fGOBPBJZxv1Z4z2+GoiqQMYmck2A8Q/3uNSehlFIYSYgEB5omELknvKPvAmJDb2pRH/+ F6DhMEMUg/qbeCdO5N5wHaX5zjmR9ZsUbkc7PZ/heJFQkxeNf3YeSTc90ozrtz+aOaEW uzi3hugQC1PZLjzsX3rse0xG449mxXf2a4Pl8djutoiqTK4KME4LXk2DB3uHNmox2Fb9 wgiw== X-Gm-Message-State: APjAAAXlzDxWUDiUaMrzCs1UqdroD5Js5UVcGP4ighZCPslY0yIQelPz ntVAqvZN7R2GdXSOlNQ/Z0ajUrY9toM= X-Google-Smtp-Source: APXvYqw+CyT9N157GmEJ+JKv8Mub8BdU1g9V6Edu2xw7pljK08sfuhP4NowP1K84gxRwVCr34s+jYQ== X-Received: by 2002:a7b:cbcd:: with SMTP id n13mr30034816wmi.104.1577644435103; Sun, 29 Dec 2019 10:33:55 -0800 (PST) Received: from localhost.localdomain (38.163.200.146.dyn.plus.net. [146.200.163.38]) by smtp.gmail.com with ESMTPSA id f207sm19667903wme.9.2019.12.29.10.33.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Dec 2019 10:33:54 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Sun, 29 Dec 2019 18:33:34 +0000 Message-Id: <20191229183341.14877-2-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191229183341.14877-1-liuwe@microsoft.com> References: <20191229183341.14877-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 1/8] x86: include xen/lib.h in guest/pvh-boot.h X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Michael Kelley , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" It needs ASSERT_UNREACHABLE. Signed-off-by: Wei Liu Acked-by: Jan Beulich --- xen/include/asm-x86/guest/pvh-boot.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xen/include/asm-x86/guest/pvh-boot.h b/xen/include/asm-x86/guest/pvh-boot.h index b8a76c4eed..48ffd1a0b1 100644 --- a/xen/include/asm-x86/guest/pvh-boot.h +++ b/xen/include/asm-x86/guest/pvh-boot.h @@ -30,6 +30,8 @@ void pvh_print_info(void); #else +#include + #define pvh_boot 0 static inline void pvh_init(multiboot_info_t **mbi, module_t **mod) From patchwork Sun Dec 29 18:33:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11312361 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 B6B3E921 for ; Sun, 29 Dec 2019 18:35:11 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9358E20748 for ; Sun, 29 Dec 2019 18:35:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OU+4AHjq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9358E20748 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ildOB-0008OP-DO; Sun, 29 Dec 2019 18:34:07 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ildOA-0008OC-3t for xen-devel@lists.xenproject.org; Sun, 29 Dec 2019 18:34:06 +0000 X-Inumbo-ID: c5bc2eb6-2a69-11ea-a1e1-bc764e2007e4 Received: from mail-wr1-x443.google.com (unknown [2a00:1450:4864:20::443]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c5bc2eb6-2a69-11ea-a1e1-bc764e2007e4; Sun, 29 Dec 2019 18:33:57 +0000 (UTC) Received: by mail-wr1-x443.google.com with SMTP id j42so30877131wrj.12 for ; Sun, 29 Dec 2019 10:33:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+T4GPsHUk9nuxqbVFm0EUaUmXOk2IzXkX+VVh/krqzU=; b=OU+4AHjqz/NAKuZI3VYv8fyUs7tnmNWY1e9EXbF6UpTk/q2Kfpj269wnHzHBSi+Ov8 ROJUPsowviVzxM2Pu3ThoKMOA60tSwm8xz1N5oby3XI3gx5viA4E+2eIYj52kFDDUs+M 4p8bKS1wStvjFBb/EuIHUI6ozSo7zfsmAu5ULUytySrLLQyAVzzOx1GCBHp5+ONNut7b BnmveNOhkmTjWSIOgd17iBaZq9KSEfNXHzld1Pu0yp89owZmjYfLVqoWrbz7C9jxqd8A 13mGnebQd84Cdeu5pUPBdpusgj+fGPAkcqUE/t4LGqD0/zvX4YXcsrBgrs1+NEjfJyow qE+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=+T4GPsHUk9nuxqbVFm0EUaUmXOk2IzXkX+VVh/krqzU=; b=pSEtyzsj/JH181F0SLHoBcV+lLp2bP4IzM7445regXASklLy/MXNAhrV/S+mGRu7BQ 2pMNehYpEqSPTqWN5zbxJgI/bWxKCvm9jYRfZUpzhW+Xm9QipgyfwXm+XNVZfU7EIMhe CZK8oJo3kQSQr4HbIpfBu4uCaElOiXIKlgn8srVi+sWEuewcBFTMWX7R7jk5vwrU9k2A 4G48jeu1duqZo2T9Sp+U/0rATv/6dK5MRPrbPv+NEo+nTgqICX6Gm9BGXDl8buPKXt8J 5xdUydTAtM1avrJ70XE6f0dRRCfVTjTUEZWIqyAVscQ+6mzmf7PQJ2NnIpuatUdMknQ/ xiTA== X-Gm-Message-State: APjAAAXJTzEZn8pm19vVqGRhVkSJasjKx1/4ujW6TFmUcLrLuhDmM4mj PNXnRNM1t4+qAX51ZJ8MEux9cdmtJlQ= X-Google-Smtp-Source: APXvYqw/YO/cDA3aZjfUEK+TEYTaZtNX+da0gMiZ1nJY681tg54LCSdhDnn212HH0uMckb6WNMu+Iw== X-Received: by 2002:adf:90e1:: with SMTP id i88mr59664807wri.95.1577644436007; Sun, 29 Dec 2019 10:33:56 -0800 (PST) Received: from localhost.localdomain (38.163.200.146.dyn.plus.net. [146.200.163.38]) by smtp.gmail.com with ESMTPSA id f207sm19667903wme.9.2019.12.29.10.33.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Dec 2019 10:33:55 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Sun, 29 Dec 2019 18:33:35 +0000 Message-Id: <20191229183341.14877-3-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191229183341.14877-1-liuwe@microsoft.com> References: <20191229183341.14877-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 2/8] x86/hyperv: detect absolutely necessary MSRs X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Michael Kelley , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" If they are not available, disable Hyper-V related features. Signed-off-by: Wei Liu Acked-by: Jan Beulich --- xen/arch/x86/guest/hyperv/hyperv.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index 2e70b4aa82..c6a26c5453 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -32,6 +32,8 @@ static const struct hypervisor_ops ops = { const struct hypervisor_ops *__init hyperv_probe(void) { uint32_t eax, ebx, ecx, edx; + uint64_t required_msrs = HV_X64_MSR_HYPERCALL_AVAILABLE | + HV_X64_MSR_VP_INDEX_AVAILABLE; cpuid(0x40000000, &eax, &ebx, &ecx, &edx); if ( !((ebx == 0x7263694d) && /* "Micr" */ @@ -57,6 +59,15 @@ const struct hypervisor_ops *__init hyperv_probe(void) ms_hyperv.max_vp_index = eax; ms_hyperv.max_lp_index = ebx; + if ( (ms_hyperv.features & required_msrs) != required_msrs ) + { + /* Oops, required MSRs are not available. Treat this as + * "Hyper-V is not available". + */ + memset(&ms_hyperv, 0, sizeof(ms_hyperv)); + return NULL; + } + return &ops; } From patchwork Sun Dec 29 18:33:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11312359 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 1D8AF14DB for ; Sun, 29 Dec 2019 18:35:11 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EE52B20748 for ; Sun, 29 Dec 2019 18:35:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SxBaX5Oi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EE52B20748 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ildOG-0008PV-Mg; Sun, 29 Dec 2019 18:34:12 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ildOF-0008PB-4b for xen-devel@lists.xenproject.org; Sun, 29 Dec 2019 18:34:11 +0000 X-Inumbo-ID: c6344626-2a69-11ea-a1e1-bc764e2007e4 Received: from mail-wm1-x341.google.com (unknown [2a00:1450:4864:20::341]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c6344626-2a69-11ea-a1e1-bc764e2007e4; Sun, 29 Dec 2019 18:33:57 +0000 (UTC) Received: by mail-wm1-x341.google.com with SMTP id a5so12404050wmb.0 for ; Sun, 29 Dec 2019 10:33:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K1Ry921yr+IZa8O5IZElaz4gVH0PBJzo0v4gt3MXWag=; b=SxBaX5Oi99rlPTZQFBkh90vrNnjhJTR1dJ5bXy0x5rQE8VN5dpKYsmbNu2bwN4uPQ5 NeUr66ukvC6JCbZb74xxlVMGC1jT+NAl2jKEIreDKrqL/HEp6Za1EebszwcYDv4E7CLn g2RksYY45PIUSZiRw23Su05N/zc6Kj7KEEUTk6yuwKD/0d0s96Kq7Beb+Tyu1cnKUSdk SeQpMJg/RJoiByKIO493sfWLb5GWGcqJFka8s88wVUcT4EuUSGkeNUDtlIUnHz9zUqF6 9908bmFIqcOxGTWkvEIqPU9DlFPEeCpLv8NUGSN1b3u/xbv9uwJuPrx5TLRxl1KmwQZw p50w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=K1Ry921yr+IZa8O5IZElaz4gVH0PBJzo0v4gt3MXWag=; b=JS7L2V/fH36MNY8xpsc08PIa/VKdw19F9cvlaH4qVKi5UBLEmcrWyZxPH+eDC+dgUv V8LlrthnIfVWUOGKxZbNpKRZoOrMHE7j5vQ4xeSkjQh05c4mO2jhEFwF5ORTiG27Hqxc R59gXlhLBVnDLi1qxvR2x+/j85UgM2ruvd4SZVWurNb4DvV4zDBx8vWb1rtiDtjfqDrQ Vh62x6qEYbxrNcuTVNyLwi4Zs/OMGcgrQrr03B7Ts4tLlD6R9qZTCU5zwRQqW78jQ2tQ aVfqzFRGOKXcWrvySA89MzaDqTueiEzzVte/6NgvlTVTsu2z1lIqgyucf+5nNOb139Iy u/aQ== X-Gm-Message-State: APjAAAXTK9DC+XsdvRnb6rPVvJqOeBjZSePTMDh05lz5UEbpvxCHS0F2 ATadLDpVsyOyyFy9Yk4S/47/fFaAcGk= X-Google-Smtp-Source: APXvYqwp/gfQzxhMttTf34WHAy7Q09gBFru8baiBnlmuTgG6CHkRNLWmp1cEwn/3fJ/AjBwj1mrDhg== X-Received: by 2002:a1c:7203:: with SMTP id n3mr28829827wmc.119.1577644436910; Sun, 29 Dec 2019 10:33:56 -0800 (PST) Received: from localhost.localdomain (38.163.200.146.dyn.plus.net. [146.200.163.38]) by smtp.gmail.com with ESMTPSA id f207sm19667903wme.9.2019.12.29.10.33.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Dec 2019 10:33:56 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Sun, 29 Dec 2019 18:33:36 +0000 Message-Id: <20191229183341.14877-4-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191229183341.14877-1-liuwe@microsoft.com> References: <20191229183341.14877-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 3/8] x86: rename guest/hypercall.h to guest/xen-hypercall.h X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Michael Kelley , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" We will provide a header file for Hyper-V hypercalls. No functional change. Signed-off-by: Wei Liu Reviewed-by: Paul Durrant Acked-by: Jan Beulich --- xen/include/asm-x86/guest.h | 2 +- xen/include/asm-x86/guest/{hypercall.h => xen-hypercall.h} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename xen/include/asm-x86/guest/{hypercall.h => xen-hypercall.h} (99%) diff --git a/xen/include/asm-x86/guest.h b/xen/include/asm-x86/guest.h index 94448606d4..7f09c643d4 100644 --- a/xen/include/asm-x86/guest.h +++ b/xen/include/asm-x86/guest.h @@ -19,11 +19,11 @@ #ifndef __X86_GUEST_H__ #define __X86_GUEST_H__ -#include #include #include #include #include +#include #include #endif /* __X86_GUEST_H__ */ diff --git a/xen/include/asm-x86/guest/hypercall.h b/xen/include/asm-x86/guest/xen-hypercall.h similarity index 99% rename from xen/include/asm-x86/guest/hypercall.h rename to xen/include/asm-x86/guest/xen-hypercall.h index d0d2f5022d..681d3aecd7 100644 --- a/xen/include/asm-x86/guest/hypercall.h +++ b/xen/include/asm-x86/guest/xen-hypercall.h @@ -1,5 +1,5 @@ /****************************************************************************** - * asm-x86/guest/hypercall.h + * asm-x86/guest/xen-hypercall.h * * This program is free software; you can redistribute it and/or * modify it under the terms and conditions of the GNU General Public From patchwork Sun Dec 29 18:33:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11312365 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 3C1A414DB for ; Sun, 29 Dec 2019 18:35:14 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 18A7820748 for ; Sun, 29 Dec 2019 18:35:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Wm0uGfM6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 18A7820748 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ildOK-0008R9-W0; Sun, 29 Dec 2019 18:34:16 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ildOK-0008Qq-43 for xen-devel@lists.xenproject.org; Sun, 29 Dec 2019 18:34:16 +0000 X-Inumbo-ID: c6ba7d36-2a69-11ea-a1e1-bc764e2007e4 Received: from mail-wm1-x343.google.com (unknown [2a00:1450:4864:20::343]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c6ba7d36-2a69-11ea-a1e1-bc764e2007e4; Sun, 29 Dec 2019 18:33:58 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id t14so12582604wmi.5 for ; Sun, 29 Dec 2019 10:33:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yUTd1JvE33R5YeeJoO6ibJUr87M2fq2cnap5F1T4Coo=; b=Wm0uGfM6hWk8ZafajtIAZFnjIh6xQ1k4yOyITXMZLz1rWcp7VujvIHAiyj+Zlvh8PA x8um2YQWFzgbKiQsD89HIdzqWuRYu+2mLkwMNPmt8u74DbLJcyVYVtV+aRuy5PPHPyYX xDjts14mKc2dtohOz5TRSyvcpc+oIu1mCqSaLpu7CCxzMqiWk6iaGxs7c4paIc+2iIZS OoEOqYF7C+qg8Py2/GHARXGErInL+YJroGTmL3xBZVwuMnBqn2bWPejpVMMtEEhsXLBg FZYh4QlPZF6Eucdo0yC5AFTAGKTnJGp+K8Zcd5bTUIj0WNsgEivwlU1JzTj6FsxCfB56 uv/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=yUTd1JvE33R5YeeJoO6ibJUr87M2fq2cnap5F1T4Coo=; b=TBrwjfdt/BC4APCbb9Gs1xYxF2AUhklSQNA+u2FBKWbHymjHMQLGbNvdd1AW095txT lF2aw5uMMMqvYPEULoAWAlQKLm87m8D93T5hvO7QqdGtI/Zqadu3Faal0kVPaoJtxEOi bwQSf1icDMNGoZ/1YX7REBuCmtxZ3+T1P3g6wvUY7osmvCm7Qnzv7T/08OqDbYrDxp9d Oag0HalVAUPg4YYTiNrkienQjlEhO6HMf4R2zwRSorEbSVTBSM0D5Nkoc5eju61TYJGQ Vnz7aiTRN4OFbviNdgRkYbXSU0BuqzSUadz0TpLSyJpFwEo1iiBhLXBBgCSXuGW+7Kiv zSfg== X-Gm-Message-State: APjAAAXkgwt1xpTXRzwatB2RcIsmdC6OES0BPpReL77Pm61fOZ8KYl/w rwKvBJdJ6J5CHKBr7y/Ov7s222JCCH0= X-Google-Smtp-Source: APXvYqxvZHLSgFp1w4L8h63Ft9w6NohjU7jzmD9SL+fwvxhj1RPLSp7MME6k71NQVXZLFxYklWeFpQ== X-Received: by 2002:a1c:3189:: with SMTP id x131mr28988125wmx.59.1577644437764; Sun, 29 Dec 2019 10:33:57 -0800 (PST) Received: from localhost.localdomain (38.163.200.146.dyn.plus.net. [146.200.163.38]) by smtp.gmail.com with ESMTPSA id f207sm19667903wme.9.2019.12.29.10.33.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Dec 2019 10:33:57 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Sun, 29 Dec 2019 18:33:37 +0000 Message-Id: <20191229183341.14877-5-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191229183341.14877-1-liuwe@microsoft.com> References: <20191229183341.14877-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 4/8] x86/hyperv: setup hypercall page X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Michael Kelley , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Signed-off-by: Wei Liu --- xen/arch/x86/guest/hyperv/hyperv.c | 41 +++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index c6a26c5453..438910c8cb 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -19,16 +19,17 @@ * Copyright (c) 2019 Microsoft. */ #include +#include #include #include struct ms_hyperv_info __read_mostly ms_hyperv; -static const struct hypervisor_ops ops = { - .name = "Hyper-V", -}; +void *hv_hypercall; +static struct page_info *hv_hypercall_page; +static const struct hypervisor_ops ops; const struct hypervisor_ops *__init hyperv_probe(void) { uint32_t eax, ebx, ecx, edx; @@ -71,6 +72,40 @@ const struct hypervisor_ops *__init hyperv_probe(void) return &ops; } +static void __init setup_hypercall_page(void) +{ + union hv_x64_msr_hypercall_contents hypercall_msr; + + /* Unfortunately there isn't a really good way to unwind Xen to + * not use Hyper-V hooks, so panic if anything goes wrong. + * + * In practice if page allocation fails this early on it is + * unlikely we can get a working system later. + */ + hv_hypercall_page = alloc_domheap_page(NULL, 0); + if ( !hv_hypercall_page ) + panic("Failed to allocate Hyper-V hypercall page\n"); + + hv_hypercall = __map_domain_page_global(hv_hypercall_page); + if ( !hv_hypercall ) + panic("Failed to map Hyper-V hypercall page\n"); + + rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + hypercall_msr.enable = 1; + hypercall_msr.guest_physical_address = page_to_maddr(hv_hypercall_page); + wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); +} + +static void __init setup(void) +{ + setup_hypercall_page(); +} + +static const struct hypervisor_ops ops = { + .name = "Hyper-V", + .setup = setup, +}; + /* * Local variables: * mode: C From patchwork Sun Dec 29 18:33:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11312367 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 7C4FA138C for ; Sun, 29 Dec 2019 18:35:16 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 58C4620748 for ; Sun, 29 Dec 2019 18:35:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JgLyZz0T" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 58C4620748 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ildOQ-0008TC-9e; Sun, 29 Dec 2019 18:34:22 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ildOP-0008Sd-3s for xen-devel@lists.xenproject.org; Sun, 29 Dec 2019 18:34:21 +0000 X-Inumbo-ID: c73e166e-2a69-11ea-a1e1-bc764e2007e4 Received: from mail-wm1-x341.google.com (unknown [2a00:1450:4864:20::341]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c73e166e-2a69-11ea-a1e1-bc764e2007e4; Sun, 29 Dec 2019 18:33:59 +0000 (UTC) Received: by mail-wm1-x341.google.com with SMTP id u2so12582280wmc.3 for ; Sun, 29 Dec 2019 10:33:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=asb9o+xNQOO3u3ZzsBKwpRrK8IPM5jQNg7xWqM9F3KI=; b=JgLyZz0TTlhU4o9sVht7VWWxB4MwDi78qPrKGJnxkdr84WHBeGEzsRQZ3n2vC+enLl 3A2yLT0aTPK8EUhUT1rer7u8iCyYG79xvZvq5DcoiRMsx7wAuYHbDyRJBmuaWcSIHdom TITyQMSlhqyECseyN4dbX3SJzK+leuMLzNKp9UiUAk0X3S6ptqBJ8wKZn6Q7XblVPnE1 zHFWeZIh8IUZGvmtxNWj7ZH9NdEKr8U6MsPy1QQhmTnuinOBFgKbPl1QOUqEGttQUwkE hhsOPHNcKyFrlBsD6kdJ6G7BI30ftu5J75l40nyK0bD1eTX2PZZ+LibszBKLR2wns0yV KPYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=asb9o+xNQOO3u3ZzsBKwpRrK8IPM5jQNg7xWqM9F3KI=; b=IefAebYaNMN58zBdYtUjXW8tVRfjNv4UO/G/sNqs9Tb5L+QqglaUvP/J89mS2Ftsiv 9Drz753tf4FuXqVotXm0l/FcZqvs86zMmhh56rUTGG5Wt29edjmVqxFEuMDimDzKp7Y+ fzGFGl9rIy9yoVdmUH98Yw4GYFSRbRbtTztt9bWvEfkl5SC5d4ulTL+G6IQP3lrV6ZtB jt3+SjjU5TN7BoZya6INrs2Ga+1ETzPHQnT4lbPTkFNTODKKDQfW98T1cUq5RcpIYxGy DSO9tL/lm3VbYmpFdZ1/c9IsNrLCxvSUjjGI0pmGxt1kNfY7ZsITXiRXhtkWSaxDzFf7 NqVg== X-Gm-Message-State: APjAAAWWAlIZALjFxnYUfknEFAaqIS9WzHtttg4xwxIIfrvUF6wrL3c+ 0ULdWzyY8TrO0knPqQs+t8eYuIUOm74= X-Google-Smtp-Source: APXvYqxK16Szy+NwFppVU3dxWcnXH2X9+bWRzo14fFbTnWTN3tHw1swQbWvNuMmBQJqcKyb4HC023w== X-Received: by 2002:a1c:4e10:: with SMTP id g16mr29792019wmh.94.1577644438582; Sun, 29 Dec 2019 10:33:58 -0800 (PST) Received: from localhost.localdomain (38.163.200.146.dyn.plus.net. [146.200.163.38]) by smtp.gmail.com with ESMTPSA id f207sm19667903wme.9.2019.12.29.10.33.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Dec 2019 10:33:58 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Sun, 29 Dec 2019 18:33:38 +0000 Message-Id: <20191229183341.14877-6-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191229183341.14877-1-liuwe@microsoft.com> References: <20191229183341.14877-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 5/8] x86/hyperv: provide Hyper-V hypercall functions X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Michael Kelley , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" These functions will be used later to make hypercalls to Hyper-V. I couldn't find reference in TLFS that Hyper-V clobbers flags and r9-r11, but Linux's commit message says it does. Err on the safe side. Signed-off-by: Wei Liu --- xen/include/asm-x86/guest/hyperv-hypercall.h | 105 +++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 xen/include/asm-x86/guest/hyperv-hypercall.h diff --git a/xen/include/asm-x86/guest/hyperv-hypercall.h b/xen/include/asm-x86/guest/hyperv-hypercall.h new file mode 100644 index 0000000000..6017123be5 --- /dev/null +++ b/xen/include/asm-x86/guest/hyperv-hypercall.h @@ -0,0 +1,105 @@ +/****************************************************************************** + * asm-x86/guest/hyperv-hypercall.h + * + * This program is free software; you can redistribute it and/or + * modify it under the terms and conditions of the GNU General Public + * License, version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; If not, see . + * + * Copyright (c) 2019 Microsoft. + */ + +#ifndef __X86_HYPERV_HYPERCALL_H__ +#define __X86_HYPERV_HYPERCALL_H__ + +#include + +#include +#include +#include + +extern void *hv_hypercall; + +static inline uint64_t hv_do_hypercall(uint64_t control, paddr_t input, paddr_t output) +{ + uint64_t status; + + if ( !hv_hypercall ) + return ~0ULL; + + asm volatile ("mov %[output], %%r8\n" + "call *%[hypercall_page]" + : "=a" (status), "+c" (control), + "+d" (input) ASM_CALL_CONSTRAINT + : [output] "rm" (output), + [hypercall_page] "m" (hv_hypercall) + : "cc", "memory", "r8", "r9", "r10", "r11"); + + return status; +} + +static inline uint64_t hv_do_fast_hypercall(uint16_t code, + uint64_t input1, uint64_t input2) +{ + uint64_t status; + uint64_t control = (uint64_t)code | HV_HYPERCALL_FAST_BIT; + + if ( !hv_hypercall ) + return ~0ULL; + + asm volatile ("mov %[input2], %%r8\n" + "call *%[hypercall_page]" + : "=a" (status), "+c" (control), + "+d" (input1) ASM_CALL_CONSTRAINT + : [input2] "rm" (input2), + [hypercall_page] "m" (hv_hypercall) + : "cc", "r8", "r9", "r10", "r11"); + + return status; +} + +static inline uint64_t hv_do_rep_hypercall(uint16_t code, uint16_t rep_count, + uint16_t varhead_size, + paddr_t input, paddr_t output) +{ + uint64_t control = code; + uint64_t status; + uint16_t rep_comp; + + control |= (uint64_t)varhead_size << HV_HYPERCALL_VARHEAD_OFFSET; + control |= (uint64_t)rep_count << HV_HYPERCALL_REP_COMP_OFFSET; + + do { + status = hv_do_hypercall(control, input, output); + if ( (status & HV_HYPERCALL_RESULT_MASK) != HV_STATUS_SUCCESS ) + break; + + rep_comp = (status & HV_HYPERCALL_REP_COMP_MASK) >> + HV_HYPERCALL_REP_COMP_OFFSET; + + control &= ~HV_HYPERCALL_REP_START_MASK; + control |= (uint64_t)rep_comp << HV_HYPERCALL_REP_COMP_OFFSET; + + } while ( rep_comp < rep_count ); + + return status; +} + +#endif /* __X86_HYPERV_HYPERCALL_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ From patchwork Sun Dec 29 18:33:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11312369 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 1F185921 for ; Sun, 29 Dec 2019 18:35:22 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F022620748 for ; Sun, 29 Dec 2019 18:35:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ad4ZNFkX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F022620748 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ildOV-00005p-Od; Sun, 29 Dec 2019 18:34:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ildOU-0008W9-4X for xen-devel@lists.xenproject.org; Sun, 29 Dec 2019 18:34:26 +0000 X-Inumbo-ID: c7d4fbc4-2a69-11ea-a1e1-bc764e2007e4 Received: from mail-wr1-x442.google.com (unknown [2a00:1450:4864:20::442]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c7d4fbc4-2a69-11ea-a1e1-bc764e2007e4; Sun, 29 Dec 2019 18:34:00 +0000 (UTC) Received: by mail-wr1-x442.google.com with SMTP id d16so30908595wre.10 for ; Sun, 29 Dec 2019 10:34:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=StyhxDStPdtUMfRwKkbsK2BEaAdOM3U2G5Vjbak1HKc=; b=ad4ZNFkXeZ49oe7phaJulphqWcCrj4QvF3WlthAxXUijKDxuqAv8jxfkgl10R+5ZwR f/OEDDRYgkOXk/+3m7qZRC8BjTXF7mCl8pDBiN/W9SR7Ub9XL3K3o1DeovbzTJaISWIP m1mnmN41TqaDhGmJex9zf1rUQZ73T9Ir66b28uvUJv7WxUCPqw60EzRYc2iwZum2A7FN /4J+kwICeFXRn4m32HApaKIYRQY/lm9usJ6BPhZwoAbHfmyKIt5NcFFDqi3e3SNtGRU/ Id2vGL30pSA6rWrMq9vx/ceYT6dQWXLV3XoEMLHR1f6KfXSEYPDgGKHmXrkO3w8ZnSkF 09fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=StyhxDStPdtUMfRwKkbsK2BEaAdOM3U2G5Vjbak1HKc=; b=T0fbyzB7XClleShFxkAE97gLJ50slSJ5Qsx7L3MaryYGxbwBxY2l/sO8spX5SSgNo6 xNkc8/RcpVDgx6ia5QgM96Oqq8Jvv4+3JVfIWMUt6mdgY1B95PQjOi7X8Opd4Coq0PTY 9+3dyw4qiD73oHP1EBGrPmuSrR5OTEhXFq4ak+0OXRvJKFSj9AciLUIYCReU5mLALCEN BT0kAtO1EOhr+SUaHky0ggephLB1IfXgZIDppFk4CX5ov4Dxja/sJJUib1hbAQ0K2d5C Fvq3HKKIAS7gLi2aFOLhZieXor3SHfRnLmw7CADePL12lS3GvN50HtZNx47vlp3jVNbT jfkQ== X-Gm-Message-State: APjAAAW1b0MXoV7Ma9MC8qXT9uBQoSlLVpyzYZyGiuNjPkLnH78rGvTY nmtU3FEs24nfm+IfV66k2zz+X/rC5sA= X-Google-Smtp-Source: APXvYqybCE4wFqLyTxmwqM75QIH48UygDKWCpeGYtU6iBh75gnOTS7eiDr1jRKDjZNqlxesQ+3JBZA== X-Received: by 2002:adf:ee45:: with SMTP id w5mr60470220wro.352.1577644439429; Sun, 29 Dec 2019 10:33:59 -0800 (PST) Received: from localhost.localdomain (38.163.200.146.dyn.plus.net. [146.200.163.38]) by smtp.gmail.com with ESMTPSA id f207sm19667903wme.9.2019.12.29.10.33.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Dec 2019 10:33:59 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Sun, 29 Dec 2019 18:33:39 +0000 Message-Id: <20191229183341.14877-7-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191229183341.14877-1-liuwe@microsoft.com> References: <20191229183341.14877-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 6/8] x86/hyperv: provide percpu hypercall input page X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Michael Kelley , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Hyper-V's input / output argument must be 8 bytes aligned an not cross page boundary. The easiest way to satisfy those requirements is to use percpu page. For the foreseeable future we only need to provide input for TLB and APIC hypercalls, so skip setting up an output page. The page tracking structure is not bound to hypercall because it is a common pattern for Xen to write guest physical address to Hyper-V while at the same time accessing the page via a pointer. We will also need to provide an ap_setup hook for secondary cpus to setup its own input page. Signed-off-by: Wei Liu Reviewed-by: Paul Durrant --- xen/arch/x86/guest/hyperv/hyperv.c | 26 ++++++++++++++++++++++++++ xen/include/asm-x86/guest/hyperv.h | 8 ++++++++ 2 files changed, 34 insertions(+) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index 438910c8cb..67667936e9 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -28,6 +28,7 @@ struct ms_hyperv_info __read_mostly ms_hyperv; void *hv_hypercall; static struct page_info *hv_hypercall_page; +DEFINE_PER_CPU_READ_MOSTLY(struct hyperv_pcpu_page, hv_pcpu_input_arg); static const struct hypervisor_ops ops; const struct hypervisor_ops *__init hyperv_probe(void) @@ -96,14 +97,39 @@ static void __init setup_hypercall_page(void) wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); } +static void setup_hypercall_pcpu_arg(void) +{ + struct page_info *pg; + void *mapping; + unsigned int cpu = smp_processor_id(); + + pg = alloc_domheap_page(NULL, 0); + if ( !pg ) + panic("Failed to setup hypercall input page for %u\n", cpu); + + mapping = __map_domain_page_global(pg); + if ( !mapping ) + panic("Failed to map hypercall input page for %u\n", cpu); + + this_cpu(hv_pcpu_input_arg).maddr = page_to_maddr(pg); + this_cpu(hv_pcpu_input_arg).mapping = mapping; +} + static void __init setup(void) { setup_hypercall_page(); + setup_hypercall_pcpu_arg(); +} + +static void ap_setup(void) +{ + setup_hypercall_pcpu_arg(); } static const struct hypervisor_ops ops = { .name = "Hyper-V", .setup = setup, + .ap_setup = ap_setup, }; /* diff --git a/xen/include/asm-x86/guest/hyperv.h b/xen/include/asm-x86/guest/hyperv.h index c7a7f32bd5..83f297468f 100644 --- a/xen/include/asm-x86/guest/hyperv.h +++ b/xen/include/asm-x86/guest/hyperv.h @@ -51,6 +51,8 @@ static inline uint64_t hv_scale_tsc(uint64_t tsc, uint64_t scale, #ifdef CONFIG_HYPERV_GUEST +#include + #include struct ms_hyperv_info { @@ -63,6 +65,12 @@ struct ms_hyperv_info { }; extern struct ms_hyperv_info ms_hyperv; +struct hyperv_pcpu_page { + paddr_t maddr; + void *mapping; +}; +DECLARE_PER_CPU(struct hyperv_pcpu_page, hv_pcpu_input_arg); + const struct hypervisor_ops *hyperv_probe(void); #else From patchwork Sun Dec 29 18:33:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11312371 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 566F0138C for ; Sun, 29 Dec 2019 18:35:28 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2F7C020748 for ; Sun, 29 Dec 2019 18:35:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mzo4iLLT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2F7C020748 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ildOa-000093-31; Sun, 29 Dec 2019 18:34:32 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ildOZ-00008S-58 for xen-devel@lists.xenproject.org; Sun, 29 Dec 2019 18:34:31 +0000 X-Inumbo-ID: c84d13c0-2a69-11ea-88e7-bc764e2007e4 Received: from mail-wr1-x441.google.com (unknown [2a00:1450:4864:20::441]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c84d13c0-2a69-11ea-88e7-bc764e2007e4; Sun, 29 Dec 2019 18:34:01 +0000 (UTC) Received: by mail-wr1-x441.google.com with SMTP id y17so30942958wrh.5 for ; Sun, 29 Dec 2019 10:34:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1PyVSClYu6+fDv7K0LaZ45jC77EsJu0qmCTArhICeFU=; b=mzo4iLLTUYldPFh730/DhrNjr8B9qAMIcr8unfvwQoC13MrSgRZ7ZFLrfQN6tJY2nw 0wQLBgjuCYNzsIruWTDKu1wjy2UZ539FSM0YbXhKEcOC7bGlEBQz8iZVX84LxrrBMcqp 5bpcFhpfbf1Lz4LrptPZQrcP+E1Ih2oQOaUR2gsIcxPJm7MkK6vI8LoAAaV5/oIa6TsD IoKA0+wkJmTXgbs0i39HYnQMGBKZVwlH/f3vkvIFiM6QXTnIvYm9OpWHn+vg5/cl/GkO fI86jdThY9wE7V8INb7BzkdvnWnljJLtf6BTAIVcN09kxqv80xDPmo6D6h0hXw+0ZJ1J ivpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=1PyVSClYu6+fDv7K0LaZ45jC77EsJu0qmCTArhICeFU=; b=rV8LeepV+DkN13PSCQSKiCUnzqbtte+YrbYxzZFGc/X5aKEuSoIOwk7CxYCs8zEDeo UVvvPd7cbqdZ9kEKfUQdRTUjDvcSIEk9ZExsqVNc94zNbFb9x4xHLS/cGUfkmNDfGQ9f FDRrgaqtQUDbknSWkn4bT1FVbY7JFD7GtdVOrcC9a5vADPfDJ7UCoHFb0dXtp7HJzawC BHP2A+dNc2LfDmBZInu5W7JoV0koEG17OYIJTs9P8GOnHtfLGqAQBRHRKPxndyTdwSmy WrHEAVDZWp1bBzhpazFsVnG7IIifMTEFLJxkkksTbIlG7ubg2EBDkiSFf9Yw7Wjc2Fgm XbNw== X-Gm-Message-State: APjAAAXqiMm6oks3cDemvS/Pp/KP2/N4mK/5pvkGE65CG9khWuAGTZvt jmbdVHF5iSsduG92O2nemxQPufa/xSs= X-Google-Smtp-Source: APXvYqxjqzOJIVTIL9UaC91HvisLkiqlLpmaBAk4pcOLatt0n4Ua8s+HZiiNR8fBGNysQNzDiRfVIw== X-Received: by 2002:a5d:51c6:: with SMTP id n6mr1352933wrv.250.1577644440417; Sun, 29 Dec 2019 10:34:00 -0800 (PST) Received: from localhost.localdomain (38.163.200.146.dyn.plus.net. [146.200.163.38]) by smtp.gmail.com with ESMTPSA id f207sm19667903wme.9.2019.12.29.10.33.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Dec 2019 10:34:00 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Sun, 29 Dec 2019 18:33:40 +0000 Message-Id: <20191229183341.14877-8-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191229183341.14877-1-liuwe@microsoft.com> References: <20191229183341.14877-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 7/8] x86/hyperv: retrieve vp_index from Hyper-V X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Michael Kelley , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This will be useful when invoking hypercall that targets specific vcpu(s). Signed-off-by: Wei Liu --- xen/arch/x86/guest/hyperv/hyperv.c | 12 ++++++++++++ xen/include/asm-x86/guest/hyperv.h | 1 + 2 files changed, 13 insertions(+) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index 67667936e9..da3a8cd85d 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -29,6 +29,7 @@ struct ms_hyperv_info __read_mostly ms_hyperv; void *hv_hypercall; static struct page_info *hv_hypercall_page; DEFINE_PER_CPU_READ_MOSTLY(struct hyperv_pcpu_page, hv_pcpu_input_arg); +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, hv_vp_index); static const struct hypervisor_ops ops; const struct hypervisor_ops *__init hyperv_probe(void) @@ -115,15 +116,26 @@ static void setup_hypercall_pcpu_arg(void) this_cpu(hv_pcpu_input_arg).mapping = mapping; } +static void setup_vp_index(void) +{ + uint64_t vp_index_msr; + + rdmsrl(HV_X64_MSR_VP_INDEX, vp_index_msr); + + this_cpu(hv_vp_index) = vp_index_msr; +} + static void __init setup(void) { setup_hypercall_page(); setup_hypercall_pcpu_arg(); + setup_vp_index(); } static void ap_setup(void) { setup_hypercall_pcpu_arg(); + setup_vp_index(); } static const struct hypervisor_ops ops = { diff --git a/xen/include/asm-x86/guest/hyperv.h b/xen/include/asm-x86/guest/hyperv.h index 83f297468f..4b635829f3 100644 --- a/xen/include/asm-x86/guest/hyperv.h +++ b/xen/include/asm-x86/guest/hyperv.h @@ -70,6 +70,7 @@ struct hyperv_pcpu_page { void *mapping; }; DECLARE_PER_CPU(struct hyperv_pcpu_page, hv_pcpu_input_arg); +DECLARE_PER_CPU(unsigned int, hv_vp_index); const struct hypervisor_ops *hyperv_probe(void); From patchwork Sun Dec 29 18:33:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11312373 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 795EE138C for ; Sun, 29 Dec 2019 18:35:32 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 562D520748 for ; Sun, 29 Dec 2019 18:35:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Sd5UeMLW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 562D520748 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ildOf-0000DK-EG; Sun, 29 Dec 2019 18:34:37 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ildOe-0000CJ-5K for xen-devel@lists.xenproject.org; Sun, 29 Dec 2019 18:34:36 +0000 X-Inumbo-ID: c8ce5a2a-2a69-11ea-88e7-bc764e2007e4 Received: from mail-wm1-x341.google.com (unknown [2a00:1450:4864:20::341]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c8ce5a2a-2a69-11ea-88e7-bc764e2007e4; Sun, 29 Dec 2019 18:34:02 +0000 (UTC) Received: by mail-wm1-x341.google.com with SMTP id b19so12372785wmj.4 for ; Sun, 29 Dec 2019 10:34:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3d0oAYCyKACs7Jy203uplvN0cNjl3u8rMIY3VL6ToB4=; b=Sd5UeMLWT/ULhIt8rsmXOfpj1l/hPLNOYGjd7XhnZ65OnTkhbxpsScWPgkWybcN6CK tU/eTPQkjAnLHePBhkZqSLBN0TDaqmC7e+mjgbWNHyJ/2SbRnwq0TZoDtXSsXonz9IEt vX6u06amFCuiYqHY2waJ0+7Q9xFruNt2z1GSR5gH1f6EEoDeTIWCyHIa/DLY6b5N51Y9 Qa81e4c+m14uHpU0+cqMYmhC9y4GYbgtirmSFr8VOdMROw4SWcZamUctlPP8Bqnrtkb5 3+e9x3B3murU62Ht3bObs12QElYJOyE7Ts8ZllFSDyUDzLjwPJ6V2HL/KVfzH2IlkoxJ oHfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=3d0oAYCyKACs7Jy203uplvN0cNjl3u8rMIY3VL6ToB4=; b=axaCYO08On3duYJAC4916xkOEuTTxeyyUzurSzk/6/JBbM0uaZ+pHU3Vl6WNP/7uHn wnBrT9RDQTZsKjcS+BklyXPYbuXc1pQ93XeMoOZdON5QWNDyzWfcRaSR65AQmNyyqtpx AGDYe1vYf5WXH19EzCH5ptD/DGWNCE0Vm2QG7jqsXf702Av43nLWO3ihN9eUPzlaSFaG j4s6jBRvNPYbEfCcQrLPsPG5OpvaFchmQrBQs37MYw513nWaxaKde5A6WFoNG8sTQubt ygDa8s0KtyCS5q1BTuFg+JEtf7isqrALF+u2yGWOv6klCL4eQ2HhvV/9iwNVaU4VjwFM lWfw== X-Gm-Message-State: APjAAAVoR59zAhou2/F4N5MOS/d/Ul4mFoTKCXPm2dZvcytULgk/8cTI eh8MW+Wh+XwsxCtvhqaR4xLJsVwC/Gw= X-Google-Smtp-Source: APXvYqyrf/tgheg5khGn4qrLjdxD4PqIp9ePYibVwAtbgqUC8fVlrdP0wLyJAoQCOpH/YXW+MITFfw== X-Received: by 2002:a7b:cfc2:: with SMTP id f2mr28916093wmm.44.1577644441234; Sun, 29 Dec 2019 10:34:01 -0800 (PST) Received: from localhost.localdomain (38.163.200.146.dyn.plus.net. [146.200.163.38]) by smtp.gmail.com with ESMTPSA id f207sm19667903wme.9.2019.12.29.10.34.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Dec 2019 10:34:00 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Sun, 29 Dec 2019 18:33:41 +0000 Message-Id: <20191229183341.14877-9-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191229183341.14877-1-liuwe@microsoft.com> References: <20191229183341.14877-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 8/8] x86/hyperv: setup VP assist page X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Michael Kelley , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" VP assist page is rather important as we need to toggle some bits in that page such that L1 guest can make hypercalls directly to L0 Hyper-V. Preemptively split out set_vp_assist page which will be used in the resume path. Signed-off-by: Wei Liu --- xen/arch/x86/guest/hyperv/hyperv.c | 35 ++++++++++++++++++++++++++++++ xen/include/asm-x86/guest/hyperv.h | 1 + 2 files changed, 36 insertions(+) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index da3a8cd85d..a88b9ae6d9 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -30,6 +30,7 @@ void *hv_hypercall; static struct page_info *hv_hypercall_page; DEFINE_PER_CPU_READ_MOSTLY(struct hyperv_pcpu_page, hv_pcpu_input_arg); DEFINE_PER_CPU_READ_MOSTLY(unsigned int, hv_vp_index); +DEFINE_PER_CPU_READ_MOSTLY(struct hyperv_pcpu_page, hv_vp_assist); static const struct hypervisor_ops ops; const struct hypervisor_ops *__init hyperv_probe(void) @@ -125,17 +126,51 @@ static void setup_vp_index(void) this_cpu(hv_vp_index) = vp_index_msr; } +static void set_vp_assist(void) +{ + uint64_t val = paddr_to_pfn(this_cpu(hv_vp_assist).maddr); + + val = (val << HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT) | + HV_X64_MSR_VP_ASSIST_PAGE_ENABLE; + + wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, val); +} + +static void setup_vp_assist(void) +{ + struct page_info *pg; + void *mapping; + unsigned int cpu = smp_processor_id(); + + pg = alloc_domheap_page(NULL, 0); + if ( !pg ) + panic("Failed to allocate vp_assist page for %u\n", cpu); + + mapping = __map_domain_page_global(pg); + if ( !mapping ) + panic("Failed to map vp_assist page for %u\n", cpu); + + clear_page(mapping); + + this_cpu(hv_vp_assist).maddr = page_to_maddr(pg); + this_cpu(hv_vp_assist).mapping = mapping; + + set_vp_assist(); +} + static void __init setup(void) { setup_hypercall_page(); setup_hypercall_pcpu_arg(); setup_vp_index(); + setup_vp_assist(); } static void ap_setup(void) { setup_hypercall_pcpu_arg(); setup_vp_index(); + setup_vp_assist(); } static const struct hypervisor_ops ops = { diff --git a/xen/include/asm-x86/guest/hyperv.h b/xen/include/asm-x86/guest/hyperv.h index 4b635829f3..917f4e02c2 100644 --- a/xen/include/asm-x86/guest/hyperv.h +++ b/xen/include/asm-x86/guest/hyperv.h @@ -71,6 +71,7 @@ struct hyperv_pcpu_page { }; DECLARE_PER_CPU(struct hyperv_pcpu_page, hv_pcpu_input_arg); DECLARE_PER_CPU(unsigned int, hv_vp_index); +DECLARE_PER_CPU(struct hyperv_pcpu_page, hv_vp_assist); const struct hypervisor_ops *hyperv_probe(void);