From patchwork Thu Nov 21 18:50:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11256831 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 016BE930 for ; Thu, 21 Nov 2019 18:51:43 +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 D19342067D for ; Thu, 21 Nov 2019 18:51:42 +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="Pvdmzp5f" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D19342067D 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 1iXrXh-00075X-3H; Thu, 21 Nov 2019 18:51:01 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iXrXf-00075H-HH for xen-devel@lists.xenproject.org; Thu, 21 Nov 2019 18:50:59 +0000 X-Inumbo-ID: d8aa9da2-0c8f-11ea-b678-bc764e2007e4 Received: from mail-wm1-x343.google.com (unknown [2a00:1450:4864:20::343]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d8aa9da2-0c8f-11ea-b678-bc764e2007e4; Thu, 21 Nov 2019 18:50:54 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id x26so4632768wmk.4 for ; Thu, 21 Nov 2019 10:50:54 -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=TWXlLe8IMt8Vs7gsl166Q3OWJ9VnuTA9ivSeF58Db7o=; b=Pvdmzp5f8fRFrvPbU0D9OD+MEjNkTmryCmBaKT+A1mWiEy6zYgiGbrgkfvu6+ib6do 8h1yaSsRgTTCtHgpfmECB4FZJYeGOS7cwASHx2EMoAqvgglYewMbv2dlfmubiPykwT5i FDHirMkogVDsUvy81GZDhyYS9eAUEccq5apRDYvLWMCG/vYQWsVkDm5WOBGaU1anjGVQ vAPgTH4Rsz52BlkyPEzYH9YeXPK/fqfW95vNrtz7l4h/QLguNYnc4C3MyOy7c5gMOsOV /T3v/2ju6wOmv3nj4ViGSNp3EWuATKng6Hp44J0g5+3ha7RO0h0mz2MsEoY669ABaLxZ rfGg== 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=TWXlLe8IMt8Vs7gsl166Q3OWJ9VnuTA9ivSeF58Db7o=; b=gluMyTKzzVb64OvVKlNDPKUUdmps1KhojGPfgo5FkneQo9JCx861BOwbdQ4a3sNMZv RknZgRvC2EOSoqNQGt9k/LhNzOWuLno7Ym1hBOjjCsCYE9j6htteCsxggk2WdpZoZrUz mnpx+bw2lj+NJB9KuIz8UJTvPvFFxdt14Ha7gtfNfew/uALyxBFxPVsKPAeSif72EebF ijjQDf+2rfQcKR5oWpsOxPQh5I8w4LESrZYStUxjOnQyRXc1AUPurez4yYSxsI1pxSCC JkNBR4j708k8eZXndhpu6r1DBfLSD4giyJPU8zhqlXBXlbqohSN905E8hgcsh5GqWt07 G42Q== X-Gm-Message-State: APjAAAXJgvd7EJcBsYkyyAi0mCbSjlwsTKSFeAG3DXnV6yAw9mT0nGoQ iti2dOHxAGcjNN6RjYLpcwIFJcyYJnI3KQ== X-Google-Smtp-Source: APXvYqzcAwIjDfYAE9dxx/6OVltsNTt4lT61svhWwLga+wa9Q0feppnp4da7WQE245eMH0hXromtEA== X-Received: by 2002:a05:600c:cf:: with SMTP id u15mr11982474wmm.60.1574362253803; Thu, 21 Nov 2019 10:50:53 -0800 (PST) Received: from debian.mshome.net (74.162.147.147.dyn.plus.net. [147.147.162.74]) by smtp.gmail.com with ESMTPSA id f24sm535776wmb.37.2019.11.21.10.50.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2019 10:50:53 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Thu, 21 Nov 2019 18:50:42 +0000 Message-Id: <20191121185049.16666-2-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191121185049.16666-1-liuwe@microsoft.com> References: <20191121185049.16666-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 1/8] x86: introduce CONFIG_GUEST and move code 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 , 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" Xen is able to run as a guest on Xen. We plan to make it able to run on Hyper-V as well. Introduce CONFIG_GUEST which is set to true if either running on Xen or Hyper-V is desired. Restructure code hierarchy for new code to come. No functional change intended. Signed-off-by: Wei Liu Reviewed-by: Roger Pau Monné Acked-by: Jan Beulich --- xen/arch/x86/Kconfig | 4 ++++ xen/arch/x86/Makefile | 2 +- xen/arch/x86/guest/Makefile | 5 +---- xen/arch/x86/guest/xen/Makefile | 4 ++++ xen/arch/x86/guest/{ => xen}/hypercall_page.S | 0 xen/arch/x86/guest/{ => xen}/pvh-boot.c | 0 xen/arch/x86/guest/{ => xen}/xen.c | 0 7 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 xen/arch/x86/guest/xen/Makefile rename xen/arch/x86/guest/{ => xen}/hypercall_page.S (100%) rename xen/arch/x86/guest/{ => xen}/pvh-boot.c (100%) rename xen/arch/x86/guest/{ => xen}/xen.c (100%) diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 28b3b4692a..867de857e8 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -161,8 +161,12 @@ config XEN_ALIGN_2M endchoice +config GUEST + bool + config XEN_GUEST def_bool n + select GUEST prompt "Xen Guest" ---help--- Support for Xen detecting when it is running under Xen. diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile index a0b2f4ab15..7da5a2631e 100644 --- a/xen/arch/x86/Makefile +++ b/xen/arch/x86/Makefile @@ -1,7 +1,7 @@ subdir-y += acpi subdir-y += cpu subdir-y += genapic -subdir-$(CONFIG_XEN_GUEST) += guest +subdir-$(CONFIG_GUEST) += guest subdir-$(CONFIG_HVM) += hvm subdir-y += mm subdir-$(CONFIG_XENOPROF) += oprofile diff --git a/xen/arch/x86/guest/Makefile b/xen/arch/x86/guest/Makefile index 26fb4b1007..6806f04947 100644 --- a/xen/arch/x86/guest/Makefile +++ b/xen/arch/x86/guest/Makefile @@ -1,4 +1 @@ -obj-y += hypercall_page.o -obj-y += xen.o - -obj-bin-$(CONFIG_PVH_GUEST) += pvh-boot.init.o +subdir-$(CONFIG_XEN_GUEST) += xen diff --git a/xen/arch/x86/guest/xen/Makefile b/xen/arch/x86/guest/xen/Makefile new file mode 100644 index 0000000000..26fb4b1007 --- /dev/null +++ b/xen/arch/x86/guest/xen/Makefile @@ -0,0 +1,4 @@ +obj-y += hypercall_page.o +obj-y += xen.o + +obj-bin-$(CONFIG_PVH_GUEST) += pvh-boot.init.o diff --git a/xen/arch/x86/guest/hypercall_page.S b/xen/arch/x86/guest/xen/hypercall_page.S similarity index 100% rename from xen/arch/x86/guest/hypercall_page.S rename to xen/arch/x86/guest/xen/hypercall_page.S diff --git a/xen/arch/x86/guest/pvh-boot.c b/xen/arch/x86/guest/xen/pvh-boot.c similarity index 100% rename from xen/arch/x86/guest/pvh-boot.c rename to xen/arch/x86/guest/xen/pvh-boot.c diff --git a/xen/arch/x86/guest/xen.c b/xen/arch/x86/guest/xen/xen.c similarity index 100% rename from xen/arch/x86/guest/xen.c rename to xen/arch/x86/guest/xen/xen.c From patchwork Thu Nov 21 18:50:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11256833 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 F38136C1 for ; Thu, 21 Nov 2019 18:51:49 +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 CF484206EC for ; Thu, 21 Nov 2019 18:51:49 +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="aAHIi/e5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CF484206EC 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 1iXrXm-00077v-C6; Thu, 21 Nov 2019 18:51:06 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iXrXk-00077T-Gt for xen-devel@lists.xenproject.org; Thu, 21 Nov 2019 18:51:04 +0000 X-Inumbo-ID: d92cbae4-0c8f-11ea-984a-bc764e2007e4 Received: from mail-wm1-x343.google.com (unknown [2a00:1450:4864:20::343]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d92cbae4-0c8f-11ea-984a-bc764e2007e4; Thu, 21 Nov 2019 18:50:55 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id z19so4949797wmk.3 for ; Thu, 21 Nov 2019 10:50:55 -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=AVP+NJX1jO0Cy8PowYlfCy2l9JmfmeIKdgyamebmLNw=; b=aAHIi/e5LtMoayj7tGilDgpdBQr4RlCktll+EQR43dc4AV4yygEVRZN6hkf9MWvf/j AzuSv3LbZ+i669P0aEvJ5hi23S1rkKUuLrlTQFNto+36213XX7J0d9gmsVqoj2kAjmGy WB58MYUmXmLDK4ToGP9mXxskvqQJ1pABDwoM+SrJOm2tfz/hg3yIVhuk7ZG/2cSdoDoc fRaEboUlycB0nuflMMaBBO3wRyjNZQq6fpBIKLwX5WQ+f4uDhqCOuo/3nczgb7A+lWuh 7EkCdF+2J39iWza3y+wDceXQQe0tBmU74miU5pCeZMUTpvGXpKJxqm9rll3jMsckv3hD sAdg== 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=AVP+NJX1jO0Cy8PowYlfCy2l9JmfmeIKdgyamebmLNw=; b=Jo9rKn1z7TA+9wHDzwbhX3fgDdCQ0UCdqUNsdLgAjK+ww0sJG7Dx7lzS4rLKGVq8df gIBEMo2Lof9UXMlQXGGjsmC4i7rhkUhCSq43xSeiLWhSj1meXKfCKiR1StTvSX8FsGto 1kj/mFv5/Kcez9Eo/RxJnlZxkC5zOMMQ34xHNS1uuFASKPoHK82f5ACDTrpiUzohsRG7 jh1em5orPS04xwM/OTC9QPwbXXZyDY+slzl6J1Mt4afevm0TVFCx47mAS+YzV7a1CLx+ xPHapRqUQEQ9UroJwbka1EE3rZLIGBqJyKvzC7157A6KMIaU9jd8JD2o7yJK2+MySQ0u zgbw== X-Gm-Message-State: APjAAAU1H9YKpgw8LnMVSHtZ9+d++4ScvErJYCQBMMcEW6c/K2j5sHUN s6E2mxB4yqidb41XnCPkh3YUGcojC73XJQ== X-Google-Smtp-Source: APXvYqzCeoi4LGaaxplQwDkcNx2KLl9bSrOW3C4CPXLXFkT2mpp1d53NoMf88EclnsNVBawgA+L66w== X-Received: by 2002:a05:600c:214a:: with SMTP id v10mr11865344wml.102.1574362254710; Thu, 21 Nov 2019 10:50:54 -0800 (PST) Received: from debian.mshome.net (74.162.147.147.dyn.plus.net. [147.147.162.74]) by smtp.gmail.com with ESMTPSA id f24sm535776wmb.37.2019.11.21.10.50.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2019 10:50:54 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Thu, 21 Nov 2019 18:50:43 +0000 Message-Id: <20191121185049.16666-3-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191121185049.16666-1-liuwe@microsoft.com> References: <20191121185049.16666-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 2/8] x86: add missing headers in 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 , 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" Include asm_defns.h because ASM_CALL_CONSTRAINT is defined there. Include xen/lib.h because we need ASSERT_UNREACHABLE. No functional change. Signed-off-by: Wei Liu Reviewed-by: Roger Pau Monné Acked-by: Jan Beulich --- xen/include/asm-x86/guest/hypercall.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xen/include/asm-x86/guest/hypercall.h b/xen/include/asm-x86/guest/hypercall.h index d548816b30..d0d2f5022d 100644 --- a/xen/include/asm-x86/guest/hypercall.h +++ b/xen/include/asm-x86/guest/hypercall.h @@ -23,6 +23,8 @@ #include +#include + #include #include #include @@ -180,6 +182,8 @@ static inline long xen_hypercall_set_evtchn_upcall_vector( #else /* CONFIG_XEN_GUEST */ +#include + #include static inline void xen_hypercall_console_write( From patchwork Thu Nov 21 18:50:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11256835 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 811FD6C1 for ; Thu, 21 Nov 2019 18:51:51 +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 5D4282067D for ; Thu, 21 Nov 2019 18:51:51 +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="M1VN5GGn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5D4282067D 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 1iXrXq-00079i-LS; Thu, 21 Nov 2019 18:51:10 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iXrXp-00079E-H5 for xen-devel@lists.xenproject.org; Thu, 21 Nov 2019 18:51:09 +0000 X-Inumbo-ID: d9ae429e-0c8f-11ea-9631-bc764e2007e4 Received: from mail-wm1-x343.google.com (unknown [2a00:1450:4864:20::343]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d9ae429e-0c8f-11ea-9631-bc764e2007e4; Thu, 21 Nov 2019 18:50:56 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id 8so4976338wmo.0 for ; Thu, 21 Nov 2019 10:50: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=Lp9dPk3GM26kCtmFBzgGz5LRW9FjTOSuocsi0vK/bvk=; b=M1VN5GGn93czJvTTl+fj7NTjiG3P7jMs/1rkeDf179J8kuqTVGZs7xhRKM7aATjbas bx0aJlgXf42VZdqri4tsmaFqSxfW6a6cO7RuK0q01DjQMlaOW1tLjW+ync9RGheIdtTU hro3h72Z+uDgENzrA3aoBqb/frQiyBCD6lYgNeZVoSZ762TJFSvpgC0rP4DUDFRYqFzf F28TEFSbgKh69AIFjcIF9Gtv62HgHijVDrlWKnmyjbcC3jhaWpZX55CDe9MmMtlv8KPA bQFYxLZq9arFgX6pJFw1Teq1vG/wxRTNP5Sikvo9urUJV7PcmojjfgWpDXZHPoq6Zvtf u4tQ== 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=Lp9dPk3GM26kCtmFBzgGz5LRW9FjTOSuocsi0vK/bvk=; b=rwscPIfZKMSAeunbpRQ51v6xDFEECXxgGmTCCL8sZ93c6kg/Ol4q70CdXeGnfAZ6AU 84gcPR9MHV7pbkkeLn04kNF/aIhSm0qcK4uKLoZNvpMMqo87GEHKXMCb4JwNloQoYSR0 a9moS/B9OotgsqVXEe1LDfzkTh4hrPS4QgxQG55+5tLKs41y5xAYa9O43kJWVqfsNDcK 4d2TLr3Gfqjgj977CV+6VLa88UxqoOoWxzYkdo8VF6O6q5bG/MJbvKT3JjoHgQ+/pA1u i/w/RrwQjTu/BuSlfYxajBNw0iTaspI8GlayYBu7KSWUNYp0W63srW0jm2la1D+ckW18 Fq2A== X-Gm-Message-State: APjAAAWjheBeoaSHgY6Kr47puEVqTR1YxOBi2ibosYvNVRowjnHc2HNp y7Qf0CQiPUbuJySHvoEipQ67WCgf0PN3Hg== X-Google-Smtp-Source: APXvYqxY9CZw7Zu4d0X3lbKELMD8ElPRO/vIXGm2iiBNVWhMiWLSNjHar5PZEfJG9BOCtGnmcly8gQ== X-Received: by 2002:a05:600c:2911:: with SMTP id i17mr11678800wmd.83.1574362255514; Thu, 21 Nov 2019 10:50:55 -0800 (PST) Received: from debian.mshome.net (74.162.147.147.dyn.plus.net. [147.147.162.74]) by smtp.gmail.com with ESMTPSA id f24sm535776wmb.37.2019.11.21.10.50.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2019 10:50:55 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Thu, 21 Nov 2019 18:50:44 +0000 Message-Id: <20191121185049.16666-4-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191121185049.16666-1-liuwe@microsoft.com> References: <20191121185049.16666-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 3/8] x86: drop hypervisor_cpuid_base 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 , 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" The only user is Xen specific code in PV shim. We can therefore export the variable directly. Move __read_mostly to its standard place while at it. Signed-off-by: Wei Liu Reviewed-by: Roger Pau Monné Acked-by: Jan Beulich --- xen/arch/x86/guest/xen/xen.c | 7 +------ xen/arch/x86/pv/shim.c | 2 +- xen/include/asm-x86/guest/xen.h | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/guest/xen/xen.c b/xen/arch/x86/guest/xen/xen.c index a329e7c886..1e37086518 100644 --- a/xen/arch/x86/guest/xen/xen.c +++ b/xen/arch/x86/guest/xen/xen.c @@ -37,7 +37,7 @@ bool __read_mostly xen_guest; -static __read_mostly uint32_t xen_cpuid_base; +uint32_t __read_mostly xen_cpuid_base; extern char hypercall_page[]; static struct rangeset *mem; @@ -297,11 +297,6 @@ int hypervisor_free_unused_page(mfn_t mfn) return rangeset_remove_range(mem, mfn_x(mfn), mfn_x(mfn)); } -uint32_t hypervisor_cpuid_base(void) -{ - return xen_cpuid_base; -} - static void ap_resume(void *unused) { map_vcpuinfo(); diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c index 35bf3945ac..351da970ef 100644 --- a/xen/arch/x86/pv/shim.c +++ b/xen/arch/x86/pv/shim.c @@ -995,7 +995,7 @@ domid_t get_initial_domain_id(void) if ( !pv_shim ) return 0; - cpuid(hypervisor_cpuid_base() + 4, &eax, &ebx, &ecx, &edx); + cpuid(xen_cpuid_base + 4, &eax, &ebx, &ecx, &edx); return (eax & XEN_HVM_CPUID_DOMID_PRESENT) ? ecx : 1; } diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xen.h index 7e04e4a7ab..b015ed1883 100644 --- a/xen/include/asm-x86/guest/xen.h +++ b/xen/include/asm-x86/guest/xen.h @@ -30,13 +30,13 @@ extern bool xen_guest; extern bool pv_console; +extern uint32_t xen_cpuid_base; void probe_hypervisor(void); void hypervisor_setup(void); void hypervisor_ap_setup(void); int hypervisor_alloc_unused_page(mfn_t *mfn); int hypervisor_free_unused_page(mfn_t mfn); -uint32_t hypervisor_cpuid_base(void); void hypervisor_resume(void); DECLARE_PER_CPU(unsigned int, vcpu_id); From patchwork Thu Nov 21 18:50:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11256837 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 4672A930 for ; Thu, 21 Nov 2019 18:51:59 +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 223512067D for ; Thu, 21 Nov 2019 18:51:59 +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="l0gZX27w" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 223512067D 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 1iXrXv-0007Bi-0k; Thu, 21 Nov 2019 18:51:15 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iXrXu-0007BR-IG for xen-devel@lists.xenproject.org; Thu, 21 Nov 2019 18:51:14 +0000 X-Inumbo-ID: da4a6124-0c8f-11ea-9631-bc764e2007e4 Received: from mail-wm1-x344.google.com (unknown [2a00:1450:4864:20::344]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id da4a6124-0c8f-11ea-9631-bc764e2007e4; Thu, 21 Nov 2019 18:50:57 +0000 (UTC) Received: by mail-wm1-x344.google.com with SMTP id y5so4925090wmi.5 for ; Thu, 21 Nov 2019 10:50: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=xiGjljNkC4GMr6WhYgoC6GU6XAbJmyqyEGay//B9pSA=; b=l0gZX27w0zztTLh2ZsWezxGTJDQB5XfFLYod2uW+lAv8fVH+FTO75y+6D72Idmef+c dQXp60VdCmOU6tdbFwQCXl7X6NizqWwAsMmKVZn/M6oHvtDffmkd3CKy8YW0PLCL5kTH oX0+ZJ8T6mUasYFECiQ1Sw1bXdPAAhHFr9KgKxA2vI1bnGWBC8nGneyx7Wj1KrSkJBwj oZCy16556Ak1YTqBBuRxUPgwb5pfDrNH6VxXPcOpwYArgmdo1Vbq1AqFywZZPA3kqyLY 9Y+ZtfhSh/r9xlxsccule35AAO/XzJMNOYP9I0lNEBb9VF47qq9sYQEk0RCkK1zqmmjZ hXNQ== 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=xiGjljNkC4GMr6WhYgoC6GU6XAbJmyqyEGay//B9pSA=; b=D8m3wDFgLqpLR8Iszuy5/+Rhggicju5snIoptLkAcFtmZH6NxF57UL5wRgJzFff+ZX GwwIp2fH54V5gtKchV/K66C7d/AJOqLtkiPRy1vysQmr1qkMxYb3Y+UWoxKRKNWUBa69 kG7ZaN2eEvb6fsNiXyn5/ly36O6fHFr61WG03TowoTCm6QS5TNwyK0PZyIFYcDLudHVc b2ci+QMIvoFqbdE4zeW5JVjDpGWoac1KsKPmuQanZlJknW4BAxM+NisT9ld7wlBE/oFO jqJXMV91vfatc5vfzC53p8lZjUZUNCu7cpxv0z4MYisjy76A7vcqes0eZ6fUCuzBns2L y8pw== X-Gm-Message-State: APjAAAUGLFDqw/PG915mqIfHk+UqqyepFkm2MME/J1n3yoQ7XrkUV/Bj Sty8rYOLSM8QF5U560GTNhEdc1IG6VbRsg== X-Google-Smtp-Source: APXvYqyQyJUyVftDjzujhh2yZGPXnKho94yS+Q/NYalTUSPOE3Yl99WpzEZ+Q3nUjjhg1WviuRnMcQ== X-Received: by 2002:a7b:c307:: with SMTP id k7mr11086092wmj.134.1574362256443; Thu, 21 Nov 2019 10:50:56 -0800 (PST) Received: from debian.mshome.net (74.162.147.147.dyn.plus.net. [147.147.162.74]) by smtp.gmail.com with ESMTPSA id f24sm535776wmb.37.2019.11.21.10.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2019 10:50:55 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Thu, 21 Nov 2019 18:50:45 +0000 Message-Id: <20191121185049.16666-5-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191121185049.16666-1-liuwe@microsoft.com> References: <20191121185049.16666-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 4/8] x86: introduce hypervisor framework 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 , 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 soon implement Hyper-V support for Xen. Add a framework for that. This requires moving some of the hypervisor_* functions from xen.h to hypervisor.h. Signed-off-by: Wei Liu Reviewed-by: Paul Durrant Acked-by: Jan Beulich --- Changes in v4: 1. Add ASSERT_UNREACHABLE to stubs. 2. Move __read_mostly. 3. Return hops directly. 4. Drop Paul's review tag. --- xen/arch/x86/guest/Makefile | 2 + xen/arch/x86/guest/hypervisor.c | 42 +++++++++++++++++ xen/include/asm-x86/guest.h | 1 + xen/include/asm-x86/guest/hypervisor.h | 62 ++++++++++++++++++++++++++ xen/include/asm-x86/guest/xen.h | 12 ----- 5 files changed, 107 insertions(+), 12 deletions(-) create mode 100644 xen/arch/x86/guest/hypervisor.c create mode 100644 xen/include/asm-x86/guest/hypervisor.h diff --git a/xen/arch/x86/guest/Makefile b/xen/arch/x86/guest/Makefile index 6806f04947..f63d64bbee 100644 --- a/xen/arch/x86/guest/Makefile +++ b/xen/arch/x86/guest/Makefile @@ -1 +1,3 @@ +obj-y += hypervisor.o + subdir-$(CONFIG_XEN_GUEST) += xen diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c new file mode 100644 index 0000000000..103feba5d8 --- /dev/null +++ b/xen/arch/x86/guest/hypervisor.c @@ -0,0 +1,42 @@ +/****************************************************************************** + * arch/x86/guest/hypervisor.c + * + * Support for detecting and running under a hypervisor. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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. + */ + +#include + +#include +#include + +static const struct hypervisor_ops __read_mostly *hops; + +const struct hypervisor_ops *hypervisor_probe(void) +{ + return hops; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/asm-x86/guest.h b/xen/include/asm-x86/guest.h index a38c6b5b3f..8e167165ae 100644 --- a/xen/include/asm-x86/guest.h +++ b/xen/include/asm-x86/guest.h @@ -20,6 +20,7 @@ #define __X86_GUEST_H__ #include +#include #include #include #include diff --git a/xen/include/asm-x86/guest/hypervisor.h b/xen/include/asm-x86/guest/hypervisor.h new file mode 100644 index 0000000000..2ab15a7108 --- /dev/null +++ b/xen/include/asm-x86/guest/hypervisor.h @@ -0,0 +1,62 @@ +/****************************************************************************** + * asm-x86/guest/hypervisor.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_HYPERVISOR_H__ +#define __X86_HYPERVISOR_H__ + +struct hypervisor_ops { + /* Name of the hypervisor */ + const char *name; + /* Main setup routine */ + void (*setup)(void); + /* AP setup */ + void (*ap_setup)(void); + /* Resume from suspension */ + void (*resume)(void); +}; + +#ifdef CONFIG_GUEST + +const struct hypervisor_ops *hypervisor_probe(void); +void hypervisor_setup(void); +void hypervisor_ap_setup(void); +void hypervisor_resume(void); + +#else + +#include +#include + +static inline const struct hypervisor_ops *hypervisor_probe(void) { return NULL; } +static inline void hypervisor_setup(void) { ASSERT_UNREACHABLE(); } +static inline void hypervisor_ap_setup(void) { ASSERT_UNREACHABLE(); } +static inline void hypervisor_resume(void) { ASSERT_UNREACHABLE(); } + +#endif /* CONFIG_GUEST */ + +#endif /* __X86_HYPERVISOR_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xen.h index b015ed1883..3145f75361 100644 --- a/xen/include/asm-x86/guest/xen.h +++ b/xen/include/asm-x86/guest/xen.h @@ -33,11 +33,8 @@ extern bool pv_console; extern uint32_t xen_cpuid_base; void probe_hypervisor(void); -void hypervisor_setup(void); -void hypervisor_ap_setup(void); int hypervisor_alloc_unused_page(mfn_t *mfn); int hypervisor_free_unused_page(mfn_t mfn); -void hypervisor_resume(void); DECLARE_PER_CPU(unsigned int, vcpu_id); DECLARE_PER_CPU(struct vcpu_info *, vcpu_info); @@ -49,15 +46,6 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info); static inline void probe_hypervisor(void) {} -static inline void hypervisor_setup(void) -{ - ASSERT_UNREACHABLE(); -} -static inline void hypervisor_ap_setup(void) -{ - ASSERT_UNREACHABLE(); -} - #endif /* CONFIG_XEN_GUEST */ #endif /* __X86_GUEST_XEN_H__ */ From patchwork Thu Nov 21 18:50:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11256843 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 8FF6F930 for ; Thu, 21 Nov 2019 18:52:15 +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 6C3A32067D for ; Thu, 21 Nov 2019 18:52:15 +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="ptxXAqqy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6C3A32067D 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 1iXrY0-0007Ef-E7; Thu, 21 Nov 2019 18:51:20 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iXrXz-0007EH-HY for xen-devel@lists.xenproject.org; Thu, 21 Nov 2019 18:51:19 +0000 X-Inumbo-ID: dab75856-0c8f-11ea-9631-bc764e2007e4 Received: from mail-wm1-x32d.google.com (unknown [2a00:1450:4864:20::32d]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id dab75856-0c8f-11ea-9631-bc764e2007e4; Thu, 21 Nov 2019 18:50:58 +0000 (UTC) Received: by mail-wm1-x32d.google.com with SMTP id u18so4928858wmc.3 for ; Thu, 21 Nov 2019 10:50: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=LK3O/o3+V3DHJGhpDMqiDmW/Ssr7NmvU9isr2SCzc0w=; b=ptxXAqqy8ro3dJL4t/nSoN1+6hRmBkHjzvFQ6bnfQInHK85Zsebpy1US9d5CNxDJcJ yU2E61X+Ys4dW33ov3X7t5quLCXGY5WOlg4fP/8OnSzciX87gm9Q087EjyvUs1RVsQpL wUmHbuxDk+mEEO8Kj9s/mARhugYhygJMSKd6W1EzpRc2m92uRdXDD8P2GMB6Vwql9yvN QsIUNFuHJFvZeICz7juxFCQPi3RQq2+n1l6Ioiyo1FFgMpD7NxhllOzeoTJq+US/0NS1 sqMgEb5xgvFXPOljXYJyTx8tKDhJhzbmssiLixprTIQcbeE8gUQ/4C0KvEHuLWfUT1gv 1k3A== 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=LK3O/o3+V3DHJGhpDMqiDmW/Ssr7NmvU9isr2SCzc0w=; b=olLux41gkg1cj2Da1pLPPxr/MooM9ZVOBgfkpdqPoV+P3sAFesK+2J1f4QcR61I8lw jeaO+O5itg/+JInIVLQJAW2z5A54pxbzQOQu4lC0MF/u6+TC5EyZ1j4mTq1ICsAQnWSn zZ2e6u268/VFNCoZNlGTThjR2WW9x3WhkHFID0NTUWwgZDfamAwECtlZ7MhVrPOGJVzB p2JUNx1JdgWHN59508j70UpNEjnFPjbrmj7swFcDknwLGJ8DjLELWyhUMI74D907QVZV Xl+EdLTuWk8Q2HaqvGf0+EoZus/CGwFaZ1d439sUOwc4CypSj/MG58bJ3uSCMB81oTV9 JVog== X-Gm-Message-State: APjAAAXtoDPv4oEjyRiFEN8+IQuIi/CMYeb8LspeTttKm2O7wwNhl9r5 8Vve56EqVz+IdNUQhJUqShIwU8cJCP/3yA== X-Google-Smtp-Source: APXvYqxWVpXt/Qc0C0cAUMlzaVQmPeT7b7SzY5KpY5MsUpZ+UblLnhPUVoKTy2oNPFEsWfnK6ebi3g== X-Received: by 2002:a1c:a512:: with SMTP id o18mr11419892wme.4.1574362257271; Thu, 21 Nov 2019 10:50:57 -0800 (PST) Received: from debian.mshome.net (74.162.147.147.dyn.plus.net. [147.147.162.74]) by smtp.gmail.com with ESMTPSA id f24sm535776wmb.37.2019.11.21.10.50.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2019 10:50:56 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Thu, 21 Nov 2019 18:50:46 +0000 Message-Id: <20191121185049.16666-6-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191121185049.16666-1-liuwe@microsoft.com> References: <20191121185049.16666-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 5/8] x86: rename hypervisor_{alloc, free}_unused_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 , 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" They are used in Xen code only. No functional change. Signed-off-by: Wei Liu Reviewed-by: Paul Durrant Acked-by: Jan Beulich --- Changes in v4: 1. Use xg_ prefix instead. 2. Drop Roger's review tag. --- xen/arch/x86/guest/xen/xen.c | 6 +++--- xen/arch/x86/pv/shim.c | 4 ++-- xen/include/asm-x86/guest/xen.h | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/guest/xen/xen.c b/xen/arch/x86/guest/xen/xen.c index 1e37086518..0f5b5267c5 100644 --- a/xen/arch/x86/guest/xen/xen.c +++ b/xen/arch/x86/guest/xen/xen.c @@ -93,7 +93,7 @@ static void map_shared_info(void) unsigned int i; unsigned long rc; - if ( hypervisor_alloc_unused_page(&mfn) ) + if ( xg_alloc_unused_page(&mfn) ) panic("unable to reserve shared info memory page\n"); xatp.gpfn = mfn_x(mfn); @@ -280,7 +280,7 @@ void hypervisor_ap_setup(void) init_evtchn(); } -int hypervisor_alloc_unused_page(mfn_t *mfn) +int xg_alloc_unused_page(mfn_t *mfn) { unsigned long m; int rc; @@ -292,7 +292,7 @@ int hypervisor_alloc_unused_page(mfn_t *mfn) return rc; } -int hypervisor_free_unused_page(mfn_t mfn) +int xg_free_unused_page(mfn_t mfn) { return rangeset_remove_range(mem, mfn_x(mfn), mfn_x(mfn)); } diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c index 351da970ef..7a898fdbe5 100644 --- a/xen/arch/x86/pv/shim.c +++ b/xen/arch/x86/pv/shim.c @@ -742,7 +742,7 @@ static long pv_shim_grant_table_op(unsigned int cmd, }; mfn_t mfn; - rc = hypervisor_alloc_unused_page(&mfn); + rc = xg_alloc_unused_page(&mfn); if ( rc ) { gprintk(XENLOG_ERR, @@ -754,7 +754,7 @@ static long pv_shim_grant_table_op(unsigned int cmd, rc = xen_hypercall_memory_op(XENMEM_add_to_physmap, &xatp); if ( rc ) { - hypervisor_free_unused_page(mfn); + xg_free_unused_page(mfn); break; } diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xen.h index 3145f75361..01dc3ee6f6 100644 --- a/xen/include/asm-x86/guest/xen.h +++ b/xen/include/asm-x86/guest/xen.h @@ -33,8 +33,8 @@ extern bool pv_console; extern uint32_t xen_cpuid_base; void probe_hypervisor(void); -int hypervisor_alloc_unused_page(mfn_t *mfn); -int hypervisor_free_unused_page(mfn_t mfn); +int xg_alloc_unused_page(mfn_t *mfn); +int xg_free_unused_page(mfn_t mfn); DECLARE_PER_CPU(unsigned int, vcpu_id); DECLARE_PER_CPU(struct vcpu_info *, vcpu_info); From patchwork Thu Nov 21 18:50:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11256839 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 55340930 for ; Thu, 21 Nov 2019 18:52:05 +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 30AF62067D for ; Thu, 21 Nov 2019 18:52:05 +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="IkngiqlT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 30AF62067D 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 1iXrY5-0007Hc-Mr; Thu, 21 Nov 2019 18:51:25 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iXrY4-0007Gy-HE for xen-devel@lists.xenproject.org; Thu, 21 Nov 2019 18:51:24 +0000 X-Inumbo-ID: db58437e-0c8f-11ea-adbe-bc764e2007e4 Received: from mail-wr1-x442.google.com (unknown [2a00:1450:4864:20::442]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id db58437e-0c8f-11ea-adbe-bc764e2007e4; Thu, 21 Nov 2019 18:50:59 +0000 (UTC) Received: by mail-wr1-x442.google.com with SMTP id s5so5768410wrw.2 for ; Thu, 21 Nov 2019 10:50: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=jmehIbWhQZXdoUxqvv2nAE9/O4n7ZGXTOOruyuVNHSs=; b=IkngiqlTkjNea7bGBPVnXACVbqM6xI4KEZgbGHD6t9H9M9yHG+zPD3jIN1fOEB1OgZ qRd3YBh4k0lSJvA+1t1IXQ19sxrAUgkxs9QU4ad4CipzpvCUpkd4/QjqIb3jtMHcrVkI Q2KlV3NvpdBVKtLnFwrTipM3FUpYQjtUixLFbspIcsLssNTfgXGgm3Ev5msgCgiGFvdF xrZiiTgsc1vrysTKaQfrXBu0VQ0nPO4zmH02W0a1XHgX/LUpDUzKDUTTbG+PDSNNsDc+ MTLTjoiKTTbJf1tKpuXjmf92usCZaAEMqFYnwYalBZJJcv4wq3rWz3sd8oYWfyPsmxjc +q7Q== 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=jmehIbWhQZXdoUxqvv2nAE9/O4n7ZGXTOOruyuVNHSs=; b=ESgvjMjaxbLflewmdLzKdjZdbFQSDn8T5wbBByq00lqpo67C2bWmRsGvz/QEiF/kxu DmiBgBvMhbHInl9W4RROHQfAQnXM3XdTEO53b/cU75kqo+kdUYv3FIR9uABgLVX4gZdk IU+6w1+3UNEGMsqYjJy5Lhdvv9Tt7uoUdrsx+fvOsXql3rN/ZjsKtCOn6TeyOi0AGNaF pV0liQVvxB1KofbuogtJ30JectwJUphzpRdPquIyfb2mSY7WJQHLAdE+7c4hCfixi9YC JMEfL+L/NyYJF4OwlQ2g/fUlHBmGM86zvcO3r651SALZ5uTkzPCLigsxzsNzfb+uISmW wlgQ== X-Gm-Message-State: APjAAAXZ8ex9l1D7pK21QnjvI+j9mhLkXCW/UpqE/Zb2ILF2qTfybkL9 QXCBIo0XWKMugpyJudZCq/JptQGa709uXw== X-Google-Smtp-Source: APXvYqy2zlru4pM8V+dttgjt7cGZa47POMDpLNWukAwn3g5e+CeRyvXcn5iZQ1t0HdIlg/zz8b+Law== X-Received: by 2002:adf:db51:: with SMTP id f17mr12500221wrj.85.1574362258219; Thu, 21 Nov 2019 10:50:58 -0800 (PST) Received: from debian.mshome.net (74.162.147.147.dyn.plus.net. [147.147.162.74]) by smtp.gmail.com with ESMTPSA id f24sm535776wmb.37.2019.11.21.10.50.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2019 10:50:57 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Thu, 21 Nov 2019 18:50:47 +0000 Message-Id: <20191121185049.16666-7-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191121185049.16666-1-liuwe@microsoft.com> References: <20191121185049.16666-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 6/8] x86: switch xen guest implementation to use hypervisor framework 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 , 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 Reviewed-by: Paul Durrant --- Changes in v4: 1. xen_probe returns address of ops directly. 2. Add __init to hypervisor_setup. 3. Drop Paul's review tag. --- xen/arch/x86/guest/hypervisor.c | 32 ++++++++++++++++++++- xen/arch/x86/guest/xen/pvh-boot.c | 2 +- xen/arch/x86/guest/xen/xen.c | 47 ++++++++++++++++++------------- xen/arch/x86/setup.c | 2 +- xen/include/asm-x86/guest/xen.h | 5 ++-- 5 files changed, 64 insertions(+), 24 deletions(-) diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c index 103feba5d8..a067cacecb 100644 --- a/xen/arch/x86/guest/hypervisor.c +++ b/xen/arch/x86/guest/hypervisor.c @@ -19,18 +19,48 @@ * Copyright (c) 2019 Microsoft. */ +#include #include #include -#include +#include static const struct hypervisor_ops __read_mostly *hops; const struct hypervisor_ops *hypervisor_probe(void) { + if ( hops ) + goto out; + + if ( !cpu_has_hypervisor ) + goto out; + + hops = xen_probe(); + if ( hops ) + goto out; + + out: return hops; } +void __init hypervisor_setup(void) +{ + if ( hops && hops->setup ) + hops->setup(); +} + +void hypervisor_ap_setup(void) +{ + if ( hops && hops->ap_setup ) + hops->ap_setup(); +} + +void hypervisor_resume(void) +{ + if ( hops && hops->resume ) + hops->resume(); +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/guest/xen/pvh-boot.c b/xen/arch/x86/guest/xen/pvh-boot.c index ca8e156f7d..498625eae0 100644 --- a/xen/arch/x86/guest/xen/pvh-boot.c +++ b/xen/arch/x86/guest/xen/pvh-boot.c @@ -103,7 +103,7 @@ void __init pvh_init(multiboot_info_t **mbi, module_t **mod) { convert_pvh_info(mbi, mod); - probe_hypervisor(); + hypervisor_probe(); ASSERT(xen_guest); get_memory_map(); diff --git a/xen/arch/x86/guest/xen/xen.c b/xen/arch/x86/guest/xen/xen.c index 0f5b5267c5..8cfe059887 100644 --- a/xen/arch/x86/guest/xen/xen.c +++ b/xen/arch/x86/guest/xen/xen.c @@ -67,22 +67,6 @@ static void __init find_xen_leaves(void) } } -void __init probe_hypervisor(void) -{ - if ( xen_guest || !cpu_has_hypervisor ) - return; - - find_xen_leaves(); - - if ( !xen_cpuid_base ) - return; - - /* Fill the hypercall page. */ - wrmsrl(cpuid_ebx(xen_cpuid_base + 2), __pa(hypercall_page)); - - xen_guest = true; -} - static void map_shared_info(void) { mfn_t mfn; @@ -245,7 +229,7 @@ static void init_evtchn(void) } } -void __init hypervisor_setup(void) +static void __init xen_setup(void) { init_memmap(); @@ -273,7 +257,7 @@ void __init hypervisor_setup(void) init_evtchn(); } -void hypervisor_ap_setup(void) +static void xen_ap_setup(void) { set_vcpu_id(); map_vcpuinfo(); @@ -303,7 +287,7 @@ static void ap_resume(void *unused) init_evtchn(); } -void hypervisor_resume(void) +static void xen_resume(void) { /* Reset shared info page. */ map_shared_info(); @@ -326,6 +310,31 @@ void hypervisor_resume(void) pv_console_init(); } +static const struct hypervisor_ops xg_ops = { + .name = "Xen", + .setup = xen_setup, + .ap_setup = xen_ap_setup, + .resume = xen_resume, +}; + +const struct hypervisor_ops * __init xen_probe(void) +{ + if ( xen_guest ) + return &xg_ops; + + find_xen_leaves(); + + if ( !xen_cpuid_base ) + return NULL; + + /* Fill the hypercall page. */ + wrmsrl(cpuid_ebx(xen_cpuid_base + 2), __pa(hypercall_page)); + + xen_guest = true; + + return &xg_ops; +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 00ee87bde5..19606d909b 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -763,7 +763,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) * allocing any xenheap structures wanted in lower memory. */ kexec_early_calculations(); - probe_hypervisor(); + hypervisor_probe(); parse_video_info(); diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xen.h index 01dc3ee6f6..db90b550a7 100644 --- a/xen/include/asm-x86/guest/xen.h +++ b/xen/include/asm-x86/guest/xen.h @@ -23,6 +23,7 @@ #include #include +#include #define XEN_shared_info ((struct shared_info *)fix_to_virt(FIX_XEN_SHARED_INFO)) @@ -32,7 +33,7 @@ extern bool xen_guest; extern bool pv_console; extern uint32_t xen_cpuid_base; -void probe_hypervisor(void); +const struct hypervisor_ops *xen_probe(void); int xg_alloc_unused_page(mfn_t *mfn); int xg_free_unused_page(mfn_t mfn); @@ -44,7 +45,7 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info); #define xen_guest 0 #define pv_console 0 -static inline void probe_hypervisor(void) {} +static inline const struct hypervisor_ops *xen_probe(void) { return NULL; } #endif /* CONFIG_XEN_GUEST */ #endif /* __X86_GUEST_XEN_H__ */ From patchwork Thu Nov 21 18:50:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11256841 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 869E56C1 for ; Thu, 21 Nov 2019 18:52:07 +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 627992067D for ; Thu, 21 Nov 2019 18:52:07 +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="rl9AWJu6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 627992067D 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 1iXrYA-0007Kz-Vy; Thu, 21 Nov 2019 18:51:30 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iXrY9-0007K7-HP for xen-devel@lists.xenproject.org; Thu, 21 Nov 2019 18:51:29 +0000 X-Inumbo-ID: dbd84f74-0c8f-11ea-b678-bc764e2007e4 Received: from mail-wr1-x443.google.com (unknown [2a00:1450:4864:20::443]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id dbd84f74-0c8f-11ea-b678-bc764e2007e4; Thu, 21 Nov 2019 18:51:00 +0000 (UTC) Received: by mail-wr1-x443.google.com with SMTP id i12so5746535wro.5 for ; Thu, 21 Nov 2019 10:51: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=lUPue3nJI1BlCj5R+fUwF507OE2ynKQH95Wp7cLyvA0=; b=rl9AWJu69RO7Wpww06KuYN/PM5btN7iuOVIeGur8pTn3ThpiikXCLuSUeESpH7pOD+ YboI4mcouxi6ygjjjew0iRLEscAlj4ySJtLiBoVd4mpNvULxDNf0J8cvUnO3u9cT17AS 6REDDnrqhkixYFlvbDoAL9DSZn2j3C86McitktZJpeDVaGToYgMLp30CrJm0IUa0/yWB 22hNGwzP1RyfmK2MuCDxEVH7qyj8gM0bTkLcImbjMUw1uZSKURIQDyBjjuu65DHwmoht EQP6Gboli/g/CE13o9Ryz4fju+G6x9cY+NPbXMQb1GB7fJn2ZvBGhRxRsodxYrD9gGn7 woCQ== 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=lUPue3nJI1BlCj5R+fUwF507OE2ynKQH95Wp7cLyvA0=; b=OrfWP5BQl5xAj0+vO6ORe220U+RUX98bs3ft0bl/qxiCgJf1M0iXoyzO6+QPfPm+Q4 sp2xRTo3X8SXsTbDDBS+15Kp6CSuB0Z42Ng7nBGL7rPyHv/e1olHqM+52H32TGu612v0 h0ghmFdAw9yUUwlU7hvdJTj4a9mdoB4psTA4L9RX/gpt4yDOrh/90ogepUMnYFsukDNR Zd6Y9N6g326AROTntT+kKt9LFStWSr+f6tT6vtmYxzSWdxELDCiISpCguimLALhFTk26 dJ1Ypy24KIiCW8JT8RxOyHAKpMIBIvnfOQ8q2tMHUb+a1v+TrWUd0Cldkjdv1B44ToBm M+TQ== X-Gm-Message-State: APjAAAVkms+ZiOCdv6Buw5IQpIyM/vQPpz7O80fkeINhY/U2B3v2Op4d Fw+yowT3kQPcFOFMKMwJvBfGcueZZv6WLA== X-Google-Smtp-Source: APXvYqzBZnQji8OBG2EMtpgCl/T/nh84H5uA+Y6VkGieSstfs7XbTrcHbi3MUg3tYmPmmk4Fb/BFNQ== X-Received: by 2002:adf:ed4b:: with SMTP id u11mr12050615wro.215.1574362259105; Thu, 21 Nov 2019 10:50:59 -0800 (PST) Received: from debian.mshome.net (74.162.147.147.dyn.plus.net. [147.147.162.74]) by smtp.gmail.com with ESMTPSA id f24sm535776wmb.37.2019.11.21.10.50.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2019 10:50:58 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Thu, 21 Nov 2019 18:50:48 +0000 Message-Id: <20191121185049.16666-8-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191121185049.16666-1-liuwe@microsoft.com> References: <20191121185049.16666-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 7/8] x86: be more verbose when running on a hypervisor 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 , 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" Also replace xen_guest with running_on_hypervisor boolean. Signed-off-by: Wei Liu --- Changes in v4: 1. Access ->name directly. 2. Drop Roger's review tag. --- xen/arch/x86/setup.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 19606d909b..123436b35a 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -689,6 +689,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) int i, j, e820_warn = 0, bytes = 0; bool acpi_boot_table_init_done = false, relocated = false; int ret; + bool running_on_hypervisor; struct ns16550_defaults ns16550 = { .data_bits = 8, .parity = 'n', @@ -763,7 +764,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) * allocing any xenheap structures wanted in lower memory. */ kexec_early_calculations(); - hypervisor_probe(); + running_on_hypervisor = !!hypervisor_probe(); parse_video_info(); @@ -788,6 +789,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) printk("Command line: %s\n", cmdline); printk("Xen image load base address: %#lx\n", xen_phys_start); + if ( running_on_hypervisor ) + printk("Running on %s\n", hypervisor_probe()->name); #ifdef CONFIG_VIDEO printk("Video information:\n"); @@ -1569,7 +1572,7 @@ void __init noreturn __start_xen(unsigned long mbi_p) max_cpus = nr_cpu_ids; } - if ( xen_guest ) + if ( running_on_hypervisor ) hypervisor_setup(); /* Low mappings were only needed for some BIOS table parsing. */ From patchwork Thu Nov 21 18:50:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11256845 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 5E7366C1 for ; Thu, 21 Nov 2019 18:52:19 +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 394AF2067D for ; Thu, 21 Nov 2019 18:52:19 +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="mgv2U2M5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 394AF2067D 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 1iXrYF-0007O9-95; Thu, 21 Nov 2019 18:51:35 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iXrYE-0007Nc-Ic for xen-devel@lists.xenproject.org; Thu, 21 Nov 2019 18:51:34 +0000 X-Inumbo-ID: dc966b44-0c8f-11ea-adbe-bc764e2007e4 Received: from mail-wr1-x443.google.com (unknown [2a00:1450:4864:20::443]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id dc966b44-0c8f-11ea-adbe-bc764e2007e4; Thu, 21 Nov 2019 18:51:01 +0000 (UTC) Received: by mail-wr1-x443.google.com with SMTP id s5so5768534wrw.2 for ; Thu, 21 Nov 2019 10:51: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=8Y3wEFzVrOaDE1M8t+K3RG5EMlTBpIvMPtQ9f0XWpzE=; b=mgv2U2M5vAudGESEew+t5Hpz66OiCpH5eY2YEE65QpaWJf3Z2VnBPNz0Pc7jCzGqtJ iIZigNpf2PaeKxWuIEnRVpntFPvVBMYqAHjFlui7XiN+d6Kllho+VwZyvVtV+fjVracL f+8j7iKQDiOEEjoPxNX+0YhQtKZ2uCvhpelrvr035v8A4sCS5jTtclnsVaG/h3FniZaD 2jqBiR1CRepjHzL7wZZSUNn6NopeuJzqb3DwI2dpRiVLB/mSSjRz7/WwIH4w+rHbEEJ3 mU0TIhrN08txT6V1G898MZRVKikxUF/z6tCf4u4BkUYCG+IjNXsLlW56KA+3+OC8khD8 Olwg== 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=8Y3wEFzVrOaDE1M8t+K3RG5EMlTBpIvMPtQ9f0XWpzE=; b=ScQbU6WDY4jcRFmZ4BLy/gdgFEN6I12tswhVWtZBQV3AdDBtUmpchG0lTPcKqOOVxb XN+abQh1kwUlWUmhdkrMBucCELjh0PTkZ44LTPOuSJdHxQ2ngQMlLJWr3pSp+BY49S/V MkgoC8CQxorJrcqgYLTCXF1MKxwd7m1WrTtHl5Awtmn7ohUvU/JkPUvNuG+0/7FsBA7Z ckHFAVDc6SK4T7AKfGOb/HbADs8IXuXyC/GbT6jvwZn/qbXz8aplKurCoGLvrZGGDgQA rwe1c+nhBtT6z7/W+Ku5SmwjFi/MlIod2NUyBBgipv9C7dVqwG9COj4kiq7NMuQSlN/4 9CnQ== X-Gm-Message-State: APjAAAVpSNyhBHPp0Go/Y2FmXp2cNfldbPwyh/58a8RW/IGRqufdIzSg 5RfRqDJMGCKZKrUtD9wjO4snVu9qXOOLPw== X-Google-Smtp-Source: APXvYqxKquMkLF9FGNgpMrZx4pKWQDMoNlBDz04Yi7jWgfkP/vEw9VKhOjUiu2xe81y72e5r6i1Klw== X-Received: by 2002:adf:db8e:: with SMTP id u14mr3743435wri.274.1574362260037; Thu, 21 Nov 2019 10:51:00 -0800 (PST) Received: from debian.mshome.net (74.162.147.147.dyn.plus.net. [147.147.162.74]) by smtp.gmail.com with ESMTPSA id f24sm535776wmb.37.2019.11.21.10.50.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2019 10:50:59 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Thu, 21 Nov 2019 18:50:49 +0000 Message-Id: <20191121185049.16666-9-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191121185049.16666-1-liuwe@microsoft.com> References: <20191121185049.16666-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 8/8] x86: introduce CONFIG_HYPERV and detection code 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 , 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 use the same code structure as we did for Xen. As starters, detect Hyper-V in probe routine. More complex functionalities will be added later. Take the chance to fix XEN_GUEST in Kconfig. Signed-off-by: Wei Liu Reviewed-by: Paul Durrant Acked-by: Jan Beulich --- Changes in V4: 1. Add comment regarding order of probe functions. 2. Adapt to changes in previous patches. --- xen/arch/x86/Kconfig | 11 ++++-- xen/arch/x86/guest/Makefile | 1 + xen/arch/x86/guest/hyperv/Makefile | 1 + xen/arch/x86/guest/hyperv/hyperv.c | 54 ++++++++++++++++++++++++++++++ xen/arch/x86/guest/hypervisor.c | 8 +++++ xen/include/asm-x86/guest.h | 1 + xen/include/asm-x86/guest/hyperv.h | 43 ++++++++++++++++++++++++ 7 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 xen/arch/x86/guest/hyperv/Makefile create mode 100644 xen/arch/x86/guest/hyperv/hyperv.c create mode 100644 xen/include/asm-x86/guest/hyperv.h diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 867de857e8..0a02b6ee3f 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -164,10 +164,17 @@ endchoice config GUEST bool +config HYPERV_GUEST + bool "Hyper-V Guest" + select GUEST + ---help--- + Support for Xen detecting when it is running under Hyper-V. + + If unsure, say N. + config XEN_GUEST - def_bool n + bool "Xen Guest" select GUEST - prompt "Xen Guest" ---help--- Support for Xen detecting when it is running under Xen. diff --git a/xen/arch/x86/guest/Makefile b/xen/arch/x86/guest/Makefile index f63d64bbee..f164196772 100644 --- a/xen/arch/x86/guest/Makefile +++ b/xen/arch/x86/guest/Makefile @@ -1,3 +1,4 @@ obj-y += hypervisor.o +subdir-$(CONFIG_HYPERV_GUEST) += hyperv subdir-$(CONFIG_XEN_GUEST) += xen diff --git a/xen/arch/x86/guest/hyperv/Makefile b/xen/arch/x86/guest/hyperv/Makefile new file mode 100644 index 0000000000..68170109a9 --- /dev/null +++ b/xen/arch/x86/guest/hyperv/Makefile @@ -0,0 +1 @@ +obj-y += hyperv.o diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c new file mode 100644 index 0000000000..916e08ff89 --- /dev/null +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -0,0 +1,54 @@ +/****************************************************************************** + * arch/x86/guest/hyperv/hyperv.c + * + * Support for detecting and running under Hyper-V. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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. + */ +#include + +#include + +static const struct hypervisor_ops hyperv_ops = { + .name = "Hyper-V", +}; + +const struct hypervisor_ops * __init hyperv_probe(void) +{ + uint32_t eax, ebx, ecx, edx; + + cpuid(0x40000000, &eax, &ebx, &ecx, &edx); + if ( !((ebx == 0x7263694d) && /* "Micr" */ + (ecx == 0x666f736f) && /* "osof" */ + (edx == 0x76482074)) ) /* "t Hv" */ + return NULL; + + cpuid(0x40000001, &eax, &ebx, &ecx, &edx); + if ( eax != 0x31237648 ) /* Hv#1 */ + return NULL; + + return &hyperv_ops; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c index a067cacecb..c293e185cc 100644 --- a/xen/arch/x86/guest/hypervisor.c +++ b/xen/arch/x86/guest/hypervisor.c @@ -39,6 +39,14 @@ const struct hypervisor_ops *hypervisor_probe(void) if ( hops ) goto out; + /* + * Detection of Hyper-V must come after Xen to avoid false positive due + * to viridian support + */ + hops = hyperv_probe(); + if ( hops ) + goto out; + out: return hops; } diff --git a/xen/include/asm-x86/guest.h b/xen/include/asm-x86/guest.h index 8e167165ae..94448606d4 100644 --- a/xen/include/asm-x86/guest.h +++ b/xen/include/asm-x86/guest.h @@ -20,6 +20,7 @@ #define __X86_GUEST_H__ #include +#include #include #include #include diff --git a/xen/include/asm-x86/guest/hyperv.h b/xen/include/asm-x86/guest/hyperv.h new file mode 100644 index 0000000000..3f88b94c77 --- /dev/null +++ b/xen/include/asm-x86/guest/hyperv.h @@ -0,0 +1,43 @@ +/****************************************************************************** + * asm-x86/guest/hyperv.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_GUEST_HYPERV_H__ +#define __X86_GUEST_HYPERV_H__ + +#ifdef CONFIG_HYPERV_GUEST + +#include + +const struct hypervisor_ops *hyperv_probe(void); + +#else + +static inline const struct hypervisor_ops *hyperv_probe(void) { return NULL; } + +#endif /* CONFIG_HYPERV_GUEST */ +#endif /* __X86_GUEST_HYPERV_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */