From patchwork Tue Jul 9 05:45:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergiy Kibrik X-Patchwork-Id: 13727270 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id A0C40C3DA41 for ; Tue, 9 Jul 2024 05:46:27 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.755725.1164168 (Exim 4.92) (envelope-from ) id 1sR3gB-0006jW-1z; Tue, 09 Jul 2024 05:46:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 755725.1164168; Tue, 09 Jul 2024 05:46:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3gA-0006jP-U2; Tue, 09 Jul 2024 05:46:18 +0000 Received: by outflank-mailman (input) for mailman id 755725; Tue, 09 Jul 2024 05:46:17 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3g9-0006jA-OJ for xen-devel@lists.xenproject.org; Tue, 09 Jul 2024 05:46:17 +0000 Received: from pb-smtp21.pobox.com (pb-smtp21.pobox.com [173.228.157.53]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8e33be2c-3db6-11ef-bbfb-fd08da9f4363; Tue, 09 Jul 2024 07:46:16 +0200 (CEST) Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 4291820009; Tue, 9 Jul 2024 01:46:14 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 2D1F220008; Tue, 9 Jul 2024 01:46:14 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from localhost (unknown [185.130.54.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id 8FA3720007; Tue, 9 Jul 2024 01:46:09 -0400 (EDT) (envelope-from sakib@darkstar.site) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 8e33be2c-3db6-11ef-bbfb-fd08da9f4363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=Yxv7us44ARpVq7KnIiwkUWU00 EVfKSndpycS1uI1RLk=; b=WXVBbWGEJaCFO36dTdyMceUUFFHsFrjkZ4Ioz6TAn w6jU1kbijrobY/jlmiA+YC36a9IiRaIRFGNWHFtkZHF6LVIsGULalxQzFlSetWml INeSwKvRrwhAIYfLANhsmVjgVqkRHXOMnlP9jx8hrZ0OWSXHaIFEp7TQ7ycQUBYN ck= From: Sergiy Kibrik To: xen-devel@lists.xenproject.org Cc: Xenia Ragiadakou , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , Xenia Ragiadakou , Sergiy Kibrik Subject: [XEN PATCH v4 01/14] x86: introduce AMD-V and Intel VT-x Kconfig options Date: Tue, 9 Jul 2024 08:45:59 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Pobox-Relay-ID: 8AEF06F4-3DB6-11EF-9DA4-DFF1FEA446E2-90055647!pb-smtp21.pobox.com From: Xenia Ragiadakou Introduce two new Kconfig options, SVM and VMX, to allow code specific to each virtualization technology to be separated and, when not required, stripped. CONFIG_SVM will be used to enable virtual machine extensions on platforms that implement the AMD Virtualization Technology (AMD-V). CONFIG_VMX will be used to enable virtual machine extensions on platforms that implement the Intel Virtualization Technology (Intel VT-x). Both features depend on HVM support. Since, at this point, disabling any of them would cause Xen to not compile, the options are enabled by default if HVM and are not selectable by the user. No functional change intended. Signed-off-by: Xenia Ragiadakou Signed-off-by: Sergiy Kibrik --- changes in v3: - tag added changes in v2: - simplify kconfig expression to def_bool HVM - keep file list in Makefile in alphabetical order changes in v1: - change kconfig option name AMD_SVM/INTEL_VMX -> SVM/VMX --- xen/arch/x86/Kconfig | 6 ++++++ xen/arch/x86/hvm/Makefile | 4 ++-- xen/arch/x86/mm/Makefile | 3 ++- xen/arch/x86/mm/hap/Makefile | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 7e03e4bc55..8c9f8431f0 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -122,6 +122,12 @@ config HVM If unsure, say Y. +config SVM + def_bool HVM + +config VMX + def_bool HVM + config XEN_SHSTK bool "Supervisor Shadow Stacks" depends on HAS_AS_CET_SS diff --git a/xen/arch/x86/hvm/Makefile b/xen/arch/x86/hvm/Makefile index 3464191544..8434badc64 100644 --- a/xen/arch/x86/hvm/Makefile +++ b/xen/arch/x86/hvm/Makefile @@ -1,5 +1,5 @@ -obj-y += svm/ -obj-y += vmx/ +obj-$(CONFIG_SVM) += svm/ +obj-$(CONFIG_VMX) += vmx/ obj-y += viridian/ obj-y += asid.o diff --git a/xen/arch/x86/mm/Makefile b/xen/arch/x86/mm/Makefile index 0803ac9297..0128ca7ab6 100644 --- a/xen/arch/x86/mm/Makefile +++ b/xen/arch/x86/mm/Makefile @@ -10,6 +10,7 @@ obj-$(CONFIG_MEM_SHARING) += mem_sharing.o obj-$(CONFIG_HVM) += nested.o obj-$(CONFIG_HVM) += p2m.o obj-y += p2m-basic.o -obj-$(CONFIG_HVM) += p2m-ept.o p2m-pod.o p2m-pt.o +obj-$(CONFIG_VMX) += p2m-ept.o +obj-$(CONFIG_HVM) += p2m-pod.o p2m-pt.o obj-y += paging.o obj-y += physmap.o diff --git a/xen/arch/x86/mm/hap/Makefile b/xen/arch/x86/mm/hap/Makefile index 8ef54b1faa..98c8a87819 100644 --- a/xen/arch/x86/mm/hap/Makefile +++ b/xen/arch/x86/mm/hap/Makefile @@ -3,4 +3,4 @@ obj-y += guest_walk_2.o obj-y += guest_walk_3.o obj-y += guest_walk_4.o obj-y += nested_hap.o -obj-y += nested_ept.o +obj-$(CONFIG_VMX) += nested_ept.o From patchwork Tue Jul 9 05:48:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergiy Kibrik X-Patchwork-Id: 13727271 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 75A36C3DA41 for ; Tue, 9 Jul 2024 05:48:39 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.755735.1164177 (Exim 4.92) (envelope-from ) id 1sR3iG-0007JS-CC; Tue, 09 Jul 2024 05:48:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 755735.1164177; Tue, 09 Jul 2024 05:48:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3iG-0007JL-9Y; Tue, 09 Jul 2024 05:48:28 +0000 Received: by outflank-mailman (input) for mailman id 755735; Tue, 09 Jul 2024 05:48:27 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3iF-0007JF-0s for xen-devel@lists.xenproject.org; Tue, 09 Jul 2024 05:48:27 +0000 Received: from pb-smtp21.pobox.com (pb-smtp21.pobox.com [173.228.157.53]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d9db6e13-3db6-11ef-8776-851b0ebba9a2; Tue, 09 Jul 2024 07:48:24 +0200 (CEST) Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 5376820012; Tue, 9 Jul 2024 01:48:21 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 3EB5220011; Tue, 9 Jul 2024 01:48:21 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from localhost (unknown [185.130.54.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id C9C0D20010; Tue, 9 Jul 2024 01:48:17 -0400 (EDT) (envelope-from sakib@darkstar.site) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d9db6e13-3db6-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=ar8Sud9602ZOgj0pi1k8W2AaU 4FGR+7Cpmq6PiXLXn4=; b=IhRN2hib2pG6Cl24zRkpYiMw9SYV7kAPpTPocuxbD o4mzgmfDTnzRhRlkVHFuz5L+L1jxiyFwMoMieJ0DnV7TiV1aybkvILFA93zXjHrb zBrIUJyg3F8ZcY2UFXXvG86nun1w8ieG9xnlQOwwcVUXpKj3Jl5c73SpKP5R1eLO 7E= From: Sergiy Kibrik To: xen-devel@lists.xenproject.org Cc: Sergiy Kibrik , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Jan Beulich , Stefano Stabellini , Xenia Ragiadakou , Tamas K Lengyel Subject: [XEN PATCH v4 02/14] x86/altp2m: add static inline stub for altp2m_vcpu_idx() Date: Tue, 9 Jul 2024 08:48:13 +0300 Message-Id: <952cb307528f16fc36a3fadbe26d83bc6805f81e.1720501197.git.Sergiy_Kibrik@epam.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Pobox-Relay-ID: D75F0E6C-3DB6-11EF-AE0E-DFF1FEA446E2-90055647!pb-smtp21.pobox.com The stub just returns 0 due to implementation of p2m_get_mem_access() for x86 & ARM expects it to be 0 when altp2m not active or not implemented. The separate stub is favoured over dynamic check for alt2pm availability inside regular altp2m_vcpu_idx() because this way we retain the possibility to later put the whole struct altp2mvcpu under CONFIG_ALTP2M. The purpose of the change is later to be able to disable altp2m support and exclude its code from the build completely, when not supported by target platform (as of now it's implemented for Intel EPT only). Signed-off-by: Sergiy Kibrik CC: Tamas K Lengyel CC: Jan Beulich --- changes in v4: - add static inline stub for altp2m_vcpu_idx() instead of using altp2m_active() check inside altp2m_vcpu_idx() as suggested by Jan - changed patch description changes in v3: - move altp2m_active() check inside altp2m_vcpu_idx() - drop changes to monitor.c - changed patch description changes in v2: - patch description changed, removed VMX mentioning - guard by altp2m_active() instead of hvm_altp2m_supported() --- xen/arch/x86/include/asm/altp2m.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/include/asm/altp2m.h b/xen/arch/x86/include/asm/altp2m.h index e5e59cbd68..c655b8a34e 100644 --- a/xen/arch/x86/include/asm/altp2m.h +++ b/xen/arch/x86/include/asm/altp2m.h @@ -37,8 +37,12 @@ static inline bool altp2m_active(const struct domain *d) return false; } +static inline uint16_t altp2m_vcpu_idx(const struct vcpu *v) +{ + return 0; +} + /* Only declaration is needed. DCE will optimise it out when linking. */ -uint16_t altp2m_vcpu_idx(const struct vcpu *v); void altp2m_vcpu_disable_ve(struct vcpu *v); #endif From patchwork Tue Jul 9 05:50:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergiy Kibrik X-Patchwork-Id: 13727272 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id A2646C2BD09 for ; Tue, 9 Jul 2024 05:50:40 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.755741.1164189 (Exim 4.92) (envelope-from ) id 1sR3kG-0000MH-UB; Tue, 09 Jul 2024 05:50:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 755741.1164189; Tue, 09 Jul 2024 05:50:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3kG-0000MA-PF; Tue, 09 Jul 2024 05:50:32 +0000 Received: by outflank-mailman (input) for mailman id 755741; Tue, 09 Jul 2024 05:50:31 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3kF-0000M0-Fv for xen-devel@lists.xenproject.org; Tue, 09 Jul 2024 05:50:31 +0000 Received: from pb-smtp21.pobox.com (pb-smtp21.pobox.com [173.228.157.53]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 252f2dee-3db7-11ef-8776-851b0ebba9a2; Tue, 09 Jul 2024 07:50:29 +0200 (CEST) Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 04C9520061; Tue, 9 Jul 2024 01:50:28 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id F084320060; Tue, 9 Jul 2024 01:50:27 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from localhost (unknown [185.130.54.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id 8A5FA20027; Tue, 9 Jul 2024 01:50:24 -0400 (EDT) (envelope-from sakib@darkstar.site) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 252f2dee-3db7-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=Fx6tEFqIZ8N4WzkD6Tx5NtM2/ EN8ecpPQC+N2RVvBqo=; b=WJEr9HTBxSnfKO8EXyk60R6SrD5rfwoh6exu9ULsi tQVHWArYF1sZPXM9MVmsrHuppP1xGpnRoRqOcXBxt4DsrDt3/KHc+muzPXm/Q2Q1 DIc+99EgsuejSH/UOyFd5iSV1nbJ1SsdviDtmD8EZdI9NrVUEFqzC2ZIXHRKphDS Lc= From: Sergiy Kibrik To: xen-devel@lists.xenproject.org Cc: Sergiy Kibrik , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Jan Beulich , Stefano Stabellini , Xenia Ragiadakou , Tamas K Lengyel Subject: [XEN PATCH v4 03/14] x86/p2m: guard altp2m routines Date: Tue, 9 Jul 2024 08:50:21 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Pobox-Relay-ID: 22EA3956-3DB7-11EF-A2A2-DFF1FEA446E2-90055647!pb-smtp21.pobox.com Initialize and bring down altp2m only when it is supported by the platform, e.g. VMX. Also guard p2m_altp2m_propagate_change(). The purpose of that is the possibility to disable altp2m support and exclude its code from the build completely, when it's not supported by the target platform. Here hvm_altp2m_supported() is being used to check for ALTP2M availability, which is only defined if HVM enabled, so a stub for that routine added for !HVM configuration as well. Signed-off-by: Sergiy Kibrik CC: Jan Beulich CC: Tamas K Lengyel Acked-by: Jan Beulich --- New changes were made to patch after Jan reviewed it, namely hvm_altp2m_supported() added for !HVM config, so I didn't put his Acked-by tag here. --- changes in v4: - added stub for hvm_altp2m_supported() and description updated accordingly changes in v3: - put hvm_altp2m_supported() first - rewrite changes to p2m_init() with less code - add tag --- xen/arch/x86/include/asm/hvm/hvm.h | 5 +++++ xen/arch/x86/mm/p2m-basic.c | 9 +++++---- xen/arch/x86/mm/p2m-ept.c | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/include/asm/hvm/hvm.h b/xen/arch/x86/include/asm/hvm/hvm.h index 1c01e22c8e..277648dd18 100644 --- a/xen/arch/x86/include/asm/hvm/hvm.h +++ b/xen/arch/x86/include/asm/hvm/hvm.h @@ -828,6 +828,11 @@ static inline bool hvm_hap_supported(void) return false; } +static inline bool hvm_altp2m_supported(void) +{ + return false; +} + static inline bool hvm_nested_virt_supported(void) { return false; diff --git a/xen/arch/x86/mm/p2m-basic.c b/xen/arch/x86/mm/p2m-basic.c index 25d27a0a9f..08007a687c 100644 --- a/xen/arch/x86/mm/p2m-basic.c +++ b/xen/arch/x86/mm/p2m-basic.c @@ -128,7 +128,7 @@ int p2m_init(struct domain *d) return rc; } - rc = p2m_init_altp2m(d); + rc = hvm_altp2m_supported() ? p2m_init_altp2m(d) : 0; if ( rc ) { p2m_teardown_hostp2m(d); @@ -197,11 +197,12 @@ void p2m_final_teardown(struct domain *d) { if ( is_hvm_domain(d) ) { + if ( hvm_altp2m_supported() ) + p2m_teardown_altp2m(d); /* - * We must tear down both of them unconditionally because - * we initialise them unconditionally. + * We must tear down nestedp2m unconditionally because + * we initialise it unconditionally. */ - p2m_teardown_altp2m(d); p2m_teardown_nestedp2m(d); } diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c index 469e27ee93..49b76e9d16 100644 --- a/xen/arch/x86/mm/p2m-ept.c +++ b/xen/arch/x86/mm/p2m-ept.c @@ -991,7 +991,7 @@ out: if ( is_epte_present(&old_entry) ) ept_free_entry(p2m, &old_entry, target); - if ( entry_written && p2m_is_hostp2m(p2m) ) + if ( hvm_altp2m_supported() && entry_written && p2m_is_hostp2m(p2m) ) { ret = p2m_altp2m_propagate_change(d, _gfn(gfn), mfn, order, p2mt, p2ma); if ( !rc ) From patchwork Tue Jul 9 05:52:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergiy Kibrik X-Patchwork-Id: 13727273 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id D8D42C2BD09 for ; Tue, 9 Jul 2024 05:52:47 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.755746.1164197 (Exim 4.92) (envelope-from ) id 1sR3mJ-0000vC-6a; Tue, 09 Jul 2024 05:52:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 755746.1164197; Tue, 09 Jul 2024 05:52:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3mJ-0000v5-3d; Tue, 09 Jul 2024 05:52:39 +0000 Received: by outflank-mailman (input) for mailman id 755746; Tue, 09 Jul 2024 05:52:38 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3mI-0000ux-EN for xen-devel@lists.xenproject.org; Tue, 09 Jul 2024 05:52:38 +0000 Received: from pb-smtp21.pobox.com (pb-smtp21.pobox.com [173.228.157.53]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 70bc522c-3db7-11ef-8776-851b0ebba9a2; Tue, 09 Jul 2024 07:52:36 +0200 (CEST) Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id A4B8820080; Tue, 9 Jul 2024 01:52:34 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 9E3952007F; Tue, 9 Jul 2024 01:52:34 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from localhost (unknown [185.130.54.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id 3436A2007E; Tue, 9 Jul 2024 01:52:30 -0400 (EDT) (envelope-from sakib@darkstar.site) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 70bc522c-3db7-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=XClnX1fucT+VwFTgQ97IxE6hD 9rsLrLAM+I/RpTKDdk=; b=pzvIskrW2rlqtK4reJyEJvmBmnB3HfL7COrkkQvg5 xqyICbKY66oOZu/4V/Vz06NO4Nk3osUOqrfefD58eXBRhBhJyE9DDvKb2l4UOZEL F3WhKaU1gHnejDNTPQcQAnq/0NxFhyO0KeUBDSf0YYROu6A2Zwc7RJ0E5F5XiWIJ eo= From: Sergiy Kibrik To: xen-devel@lists.xenproject.org Cc: Sergiy Kibrik , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Jan Beulich , Stefano Stabellini , Xenia Ragiadakou , Tamas K Lengyel Subject: [XEN PATCH v4 04/14] x86: introduce CONFIG_ALTP2M Kconfig option Date: Tue, 9 Jul 2024 08:52:27 +0300 Message-Id: <914561d1ae92aa84d22785f959a73434a491bdd6.1720501197.git.Sergiy_Kibrik@epam.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Pobox-Relay-ID: 6E66B8BE-3DB7-11EF-BD9F-DFF1FEA446E2-90055647!pb-smtp21.pobox.com Add new option to make altp2m code inclusion optional. Currently altp2m implemented for Intel EPT only, so option is dependant on VMX. Also the prompt itself depends on EXPERT=y, so that option is available for fine-tuning, if one want to play around with it. Use this option instead of more generic CONFIG_HVM option. That implies the possibility to build hvm code without altp2m support, hence we need to declare altp2m routines for hvm code to compile successfully (altp2m_vcpu_initialise(), altp2m_vcpu_destroy(), altp2m_vcpu_enable_ve()) Also guard altp2m routines, so that they can be disabled completely in the build -- when target platform does not actually support altp2m (AMD-V & ARM as of now). Signed-off-by: Sergiy Kibrik CC: Tamas K Lengyel CC: Jan Beulich CC: Stefano Stabellini Reviewed-by: Jan Beulich --- changes in v4: - move static inline stub for p2m_altp2m_check() from under CONFIG_HVM under CONFIG_ALTP2M - keep AP2MGET_prepopulate/AP2MGET_query under CONFIG_ALTP2M as Jan suggested changes in v3: - added help text - use conditional prompt depending on EXPERT=y - corrected & extended patch description - put a blank line before #ifdef CONFIG_ALTP2M - sqashed in a separate patch for guarding altp2m code with CONFIG_ALTP2M option changes in v2: - use separate CONFIG_ALTP2M option instead of CONFIG_VMX --- xen/arch/x86/Kconfig | 11 +++++++++++ xen/arch/x86/include/asm/altp2m.h | 5 ++++- xen/arch/x86/include/asm/hvm/hvm.h | 2 +- xen/arch/x86/include/asm/p2m.h | 23 ++++++++++++++++++----- xen/arch/x86/mm/Makefile | 2 +- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 8c9f8431f0..4a35c43dc5 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -358,6 +358,17 @@ config REQUIRE_NX was unavailable. However, if enabled, Xen will no longer boot on any CPU which is lacking NX support. +config ALTP2M + bool "Alternate P2M support" if EXPERT + default y + depends on VMX + help + Alternate-p2m allows a guest to manage multiple p2m guest physical + "memory views" (as opposed to a single p2m). + Useful for memory introspection. + + If unsure, stay with defaults. + endmenu source "common/Kconfig" diff --git a/xen/arch/x86/include/asm/altp2m.h b/xen/arch/x86/include/asm/altp2m.h index c655b8a34e..d498ebcd7c 100644 --- a/xen/arch/x86/include/asm/altp2m.h +++ b/xen/arch/x86/include/asm/altp2m.h @@ -7,7 +7,7 @@ #ifndef __ASM_X86_ALTP2M_H #define __ASM_X86_ALTP2M_H -#ifdef CONFIG_HVM +#ifdef CONFIG_ALTP2M #include #include /* for struct vcpu, struct domain */ @@ -43,6 +43,9 @@ static inline uint16_t altp2m_vcpu_idx(const struct vcpu *v) } /* Only declaration is needed. DCE will optimise it out when linking. */ +void altp2m_vcpu_initialise(struct vcpu *v); +void altp2m_vcpu_destroy(struct vcpu *v); +int altp2m_vcpu_enable_ve(struct vcpu *v, gfn_t gfn); void altp2m_vcpu_disable_ve(struct vcpu *v); #endif diff --git a/xen/arch/x86/include/asm/hvm/hvm.h b/xen/arch/x86/include/asm/hvm/hvm.h index 277648dd18..34824af6df 100644 --- a/xen/arch/x86/include/asm/hvm/hvm.h +++ b/xen/arch/x86/include/asm/hvm/hvm.h @@ -670,7 +670,7 @@ static inline bool hvm_hap_supported(void) /* returns true if hardware supports alternate p2m's */ static inline bool hvm_altp2m_supported(void) { - return hvm_funcs.caps.altp2m; + return IS_ENABLED(CONFIG_ALTP2M) && hvm_funcs.caps.altp2m; } /* Returns true if we have the minimum hardware requirements for nested virt */ diff --git a/xen/arch/x86/include/asm/p2m.h b/xen/arch/x86/include/asm/p2m.h index c1478ffc36..e6de37f108 100644 --- a/xen/arch/x86/include/asm/p2m.h +++ b/xen/arch/x86/include/asm/p2m.h @@ -577,7 +577,7 @@ static inline gfn_t mfn_to_gfn(const struct domain *d, mfn_t mfn) return _gfn(mfn_x(mfn)); } -#ifdef CONFIG_HVM +#ifdef CONFIG_ALTP2M #define AP2MGET_prepopulate true #define AP2MGET_query false @@ -589,6 +589,16 @@ static inline gfn_t mfn_to_gfn(const struct domain *d, mfn_t mfn) int altp2m_get_effective_entry(struct p2m_domain *ap2m, gfn_t gfn, mfn_t *mfn, p2m_type_t *t, p2m_access_t *a, bool prepopulate); +#else +static inline int _altp2m_get_effective_entry(struct p2m_domain *ap2m, + gfn_t gfn, mfn_t *mfn, + p2m_type_t *t, p2m_access_t *a) +{ + ASSERT_UNREACHABLE(); + return -EOPNOTSUPP; +} +#define altp2m_get_effective_entry(ap2m, gfn, mfn, t, a, prepopulate) \ + _altp2m_get_effective_entry(ap2m, gfn, mfn, t, a) #endif /* Init the datastructures for later use by the p2m code */ @@ -914,9 +924,6 @@ static inline bool p2m_set_altp2m(struct vcpu *v, unsigned int idx) /* Switch alternate p2m for a single vcpu */ bool p2m_switch_vcpu_altp2m_by_id(struct vcpu *v, unsigned int idx); -/* Check to see if vcpu should be switched to a different p2m. */ -void p2m_altp2m_check(struct vcpu *v, uint16_t idx); - /* Flush all the alternate p2m's for a domain */ void p2m_flush_altp2m(struct domain *d); @@ -952,9 +959,15 @@ int p2m_set_altp2m_view_visibility(struct domain *d, unsigned int altp2m_idx, uint8_t visible); #else /* !CONFIG_HVM */ struct p2m_domain *p2m_get_altp2m(struct vcpu *v); -static inline void p2m_altp2m_check(struct vcpu *v, uint16_t idx) {} #endif /* CONFIG_HVM */ +#ifdef CONFIG_ALTP2M +/* Check to see if vcpu should be switched to a different p2m. */ +void p2m_altp2m_check(struct vcpu *v, uint16_t idx); +#else +static inline void p2m_altp2m_check(struct vcpu *v, uint16_t idx) {} +#endif + /* p2m access to IOMMU flags */ static inline unsigned int p2m_access_to_iommu_flags(p2m_access_t p2ma) { diff --git a/xen/arch/x86/mm/Makefile b/xen/arch/x86/mm/Makefile index 0128ca7ab6..d7d57b8190 100644 --- a/xen/arch/x86/mm/Makefile +++ b/xen/arch/x86/mm/Makefile @@ -1,7 +1,7 @@ obj-y += shadow/ obj-$(CONFIG_HVM) += hap/ -obj-$(CONFIG_HVM) += altp2m.o +obj-$(CONFIG_ALTP2M) += altp2m.o obj-$(CONFIG_HVM) += guest_walk_2.o guest_walk_3.o guest_walk_4.o obj-$(CONFIG_SHADOW_PAGING) += guest_walk_4.o obj-$(CONFIG_MEM_ACCESS) += mem_access.o From patchwork Tue Jul 9 05:54:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergiy Kibrik X-Patchwork-Id: 13727274 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id B5AC7C2BD09 for ; Tue, 9 Jul 2024 05:54:55 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.755751.1164209 (Exim 4.92) (envelope-from ) id 1sR3oJ-0001T4-KF; Tue, 09 Jul 2024 05:54:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 755751.1164209; Tue, 09 Jul 2024 05:54:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3oJ-0001Sx-FA; Tue, 09 Jul 2024 05:54:43 +0000 Received: by outflank-mailman (input) for mailman id 755751; Tue, 09 Jul 2024 05:54:42 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3oI-0001So-JW for xen-devel@lists.xenproject.org; Tue, 09 Jul 2024 05:54:42 +0000 Received: from pb-smtp2.pobox.com (pb-smtp2.pobox.com [64.147.108.71]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id babed62a-3db7-11ef-8776-851b0ebba9a2; Tue, 09 Jul 2024 07:54:40 +0200 (CEST) Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id E72AB26FC2; Tue, 9 Jul 2024 01:54:38 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id CE49926FC1; Tue, 9 Jul 2024 01:54:38 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from localhost (unknown [185.130.54.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id 440D226FC0; Tue, 9 Jul 2024 01:54:37 -0400 (EDT) (envelope-from sakib@darkstar.site) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: babed62a-3db7-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=DDNDkiZVLdutMBS7Fc+YynLKX qz7hyMKSP5XW4Bwk6o=; b=vK63Z7oPVwGdF/tt9S48HYUwtZIToqrBQ/gTC6LCp cD3E6pWlaJPcU0y15uIVj/wwocIBvd9hyY7U16TW21sv1c67x7OLJSQHS4U1x/Gz itOHJ+P+EMuY6kBLPRgQDkf8raTlzAuYzxTay//o1gelp4QBwR9bvHMJRfByRv2a 3g= From: Sergiy Kibrik To: xen-devel@lists.xenproject.org Cc: Sergiy Kibrik , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Jan Beulich , Stefano Stabellini , Xenia Ragiadakou Subject: [XEN PATCH v4 05/14] x86: introduce using_{svm,vmx}() helpers Date: Tue, 9 Jul 2024 08:54:34 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Pobox-Relay-ID: B98AD47E-3DB7-11EF-8880-965B910A682E-90055647!pb-smtp2.pobox.com As we now have SVM/VMX config options for enabling/disabling these features completely in the build, we need some build-time checks to ensure that vmx/svm code can be used and things compile. Macros cpu_has_{svm,vmx} used to be doing such checks at runtime, however they do not check if SVM/VMX support is enabled in the build. Also cpu_has_{svm,vmx} can potentially be called from non-{VMX,SVM} build yet running on {VMX,SVM}-enabled CPU, so would correctly indicate that VMX/SVM is indeed supported by CPU, but code to drive it can't be used. New routines using_{vmx,svm}() indicate that both CPU _and_ build provide corresponding technology support, while cpu_has_{vmx,svm} still remains for informational runtime purpose, just as their naming suggests. These new helpers are used right away in several sites, namely guard calls to start_nested_{svm,vmx} and start_{svm,vmx} to fix a build when VMX=n or SVM=n. Signed-off-by: Sergiy Kibrik CC: Jan Beulich Reviewed-by: Jan Beulich --- changes in v4: - make using_{vmx,svm} static inline functions instead of macros - squash patch with 2 other patches where using_{vmx,svm} are being used - changed patch description changes in v3: - introduce separate macros instead of modifying behaviour of cpu_has_{vmx,svm} --- xen/arch/x86/hvm/hvm.c | 4 ++-- xen/arch/x86/hvm/nestedhvm.c | 4 ++-- xen/arch/x86/include/asm/hvm/hvm.h | 10 ++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 7f4b627b1f..057c61b4c3 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -155,9 +155,9 @@ static int __init cf_check hvm_enable(void) { const struct hvm_function_table *fns = NULL; - if ( cpu_has_vmx ) + if ( using_vmx() ) fns = start_vmx(); - else if ( cpu_has_svm ) + else if ( using_svm() ) fns = start_svm(); if ( fns == NULL ) diff --git a/xen/arch/x86/hvm/nestedhvm.c b/xen/arch/x86/hvm/nestedhvm.c index 451c4da6d4..5009167372 100644 --- a/xen/arch/x86/hvm/nestedhvm.c +++ b/xen/arch/x86/hvm/nestedhvm.c @@ -155,9 +155,9 @@ static int __init cf_check nestedhvm_setup(void) * done, so that if (for example) HAP is disabled, nested virt is * disabled as well. */ - if ( cpu_has_vmx ) + if ( using_vmx() ) start_nested_vmx(&hvm_funcs); - else if ( cpu_has_svm ) + else if ( using_svm() ) start_nested_svm(&hvm_funcs); return 0; diff --git a/xen/arch/x86/include/asm/hvm/hvm.h b/xen/arch/x86/include/asm/hvm/hvm.h index 34824af6df..2927a2ad6c 100644 --- a/xen/arch/x86/include/asm/hvm/hvm.h +++ b/xen/arch/x86/include/asm/hvm/hvm.h @@ -363,6 +363,16 @@ int hvm_copy_context_and_params(struct domain *dst, struct domain *src); int hvm_get_param(struct domain *d, uint32_t index, uint64_t *value); +static inline bool using_vmx(void) +{ + return IS_ENABLED(CONFIG_VMX) && cpu_has_vmx; +} + +static inline bool using_svm(void) +{ + return IS_ENABLED(CONFIG_SVM) && cpu_has_svm; +} + #ifdef CONFIG_HVM #define hvm_get_guest_tsc(v) hvm_get_guest_tsc_fixed(v, 0) From patchwork Tue Jul 9 05:56:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergiy Kibrik X-Patchwork-Id: 13727275 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id BA406C3DA41 for ; Tue, 9 Jul 2024 05:56:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.755763.1164219 (Exim 4.92) (envelope-from ) id 1sR3qL-00029M-Uc; Tue, 09 Jul 2024 05:56:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 755763.1164219; Tue, 09 Jul 2024 05:56:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3qL-00029F-QF; Tue, 09 Jul 2024 05:56:49 +0000 Received: by outflank-mailman (input) for mailman id 755763; Tue, 09 Jul 2024 05:56:48 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3qK-0001zP-Bp for xen-devel@lists.xenproject.org; Tue, 09 Jul 2024 05:56:48 +0000 Received: from pb-smtp21.pobox.com (pb-smtp21.pobox.com [173.228.157.53]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0654c391-3db8-11ef-bbfb-fd08da9f4363; Tue, 09 Jul 2024 07:56:47 +0200 (CEST) Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id BF69D200AB; Tue, 9 Jul 2024 01:56:45 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id B7167200AA; Tue, 9 Jul 2024 01:56:45 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from localhost (unknown [185.130.54.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id 51580200A9; Tue, 9 Jul 2024 01:56:42 -0400 (EDT) (envelope-from sakib@darkstar.site) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0654c391-3db8-11ef-bbfb-fd08da9f4363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=PZhVY9LIzVXZ4htpEIfnL3NvI 7Nfr1WjFpp0WOKYq8E=; b=pmcakE4hRD2kxNMVBqE88T7zF3Oc3gMwA9E8EtXMV hINC87/+j6Dqzi4vGCD/RXy1IP4QoZzX5V+nxvrpOPO+RgHvzfkvcavrzjP8UDDl a/HEdbUuuh607wEPbKtEmJvvPSuTAyvEPBBM3bAIHwi42srmVleGho8UKkN4rtJ4 cY= From: Sergiy Kibrik To: xen-devel@lists.xenproject.org Cc: Xenia Ragiadakou , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , Xenia Ragiadakou , Sergiy Kibrik Subject: [XEN PATCH v4 06/14] x86/p2m: guard EPT functions with using_vmx() check Date: Tue, 9 Jul 2024 08:56:38 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Pobox-Relay-ID: 04140D3A-3DB8-11EF-A90D-DFF1FEA446E2-90055647!pb-smtp21.pobox.com From: Xenia Ragiadakou Replace cpu_has_vmx check with using_vmx(), so that we do check if functions ept_p2m_init() and ept_p2m_uninit() can be called. Since currently Intel EPT implementation depends on CONFIG_VMX config option, when VMX is off these functions are unavailable. Signed-off-by: Xenia Ragiadakou Signed-off-by: Sergiy Kibrik Acked-by: Jan Beulich --- changes in v4: - changed description a bit - added tag - adjusted call to using_vmx(), as it has become an inline function changes in v3: - using_vmx instead of IS_ENABLED(CONFIG_VMX) - updated description --- xen/arch/x86/mm/p2m-basic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/mm/p2m-basic.c b/xen/arch/x86/mm/p2m-basic.c index 08007a687c..e126fda267 100644 --- a/xen/arch/x86/mm/p2m-basic.c +++ b/xen/arch/x86/mm/p2m-basic.c @@ -40,7 +40,7 @@ static int p2m_initialise(struct domain *d, struct p2m_domain *p2m) p2m_pod_init(p2m); p2m_nestedp2m_init(p2m); - if ( hap_enabled(d) && cpu_has_vmx ) + if ( hap_enabled(d) && using_vmx() ) ret = ept_p2m_init(p2m); else p2m_pt_init(p2m); @@ -72,7 +72,7 @@ struct p2m_domain *p2m_init_one(struct domain *d) void p2m_free_one(struct p2m_domain *p2m) { p2m_free_logdirty(p2m); - if ( hap_enabled(p2m->domain) && cpu_has_vmx ) + if ( hap_enabled(p2m->domain) && using_vmx() ) ept_p2m_uninit(p2m); free_cpumask_var(p2m->dirty_cpumask); xfree(p2m); From patchwork Tue Jul 9 05:58:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergiy Kibrik X-Patchwork-Id: 13727276 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id BCA5CC2BD09 for ; Tue, 9 Jul 2024 05:59:07 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.755769.1164228 (Exim 4.92) (envelope-from ) id 1sR3sR-00036Z-7n; Tue, 09 Jul 2024 05:58:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 755769.1164228; Tue, 09 Jul 2024 05:58:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3sR-00036S-4l; Tue, 09 Jul 2024 05:58:59 +0000 Received: by outflank-mailman (input) for mailman id 755769; Tue, 09 Jul 2024 05:58:57 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3sP-000356-K6 for xen-devel@lists.xenproject.org; Tue, 09 Jul 2024 05:58:57 +0000 Received: from pb-smtp20.pobox.com (pb-smtp20.pobox.com [173.228.157.52]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 525da89d-3db8-11ef-8776-851b0ebba9a2; Tue, 09 Jul 2024 07:58:55 +0200 (CEST) Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id E440138271; Tue, 9 Jul 2024 01:58:52 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id DBCFC38270; Tue, 9 Jul 2024 01:58:52 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from localhost (unknown [185.130.54.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id A41F03826E; Tue, 9 Jul 2024 01:58:48 -0400 (EDT) (envelope-from sakib@darkstar.site) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 525da89d-3db8-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=+Yl11oadxrSru19AkHHp51vGZ ym9OE6VsrHHN87lIL4=; b=QQuqpJfnKq+IF2Lu8XKoD6G+RFzkILLwFW8YgiNXz rEbYCNUOUvcXDsI9X1iWsaV8moErdio4QYW6ZMmGOvIuI5tVRqli5h4cm1RYgZFg LN1plZNT+/S172eM0+xcl2EQQMJ7epAP5GEmCJ79g+gxNOyEpEs2aIoLKqIvjNfI VE= From: Sergiy Kibrik To: xen-devel@lists.xenproject.org Cc: Xenia Ragiadakou , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , Xenia Ragiadakou , Sergiy Kibrik Subject: [XEN PATCH v4 07/14] x86/traps: guard vmx specific functions with usinc_vmx() check Date: Tue, 9 Jul 2024 08:58:45 +0300 Message-Id: <5c90e9fcffca0e730c8488935028e6cd6ab917c4.1720501197.git.Sergiy_Kibrik@epam.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Pobox-Relay-ID: 4F6271FA-3DB8-11EF-BF52-C38742FD603B-90055647!pb-smtp20.pobox.com From: Xenia Ragiadakou Replace cpu_has_vmx check with using_vmx(), so that not only VMX support in CPU is being checked at runtime, but also at build time we ensure the availability of functions vmx_vmcs_enter() & vmx_vmcs_exit(). Also since CONFIG_VMX is checked in using_vmx and it depends on CONFIG_HVM, we can drop #ifdef CONFIG_HVM lines around using_vmx. Signed-off-by: Xenia Ragiadakou Signed-off-by: Sergiy Kibrik Acked-by: Jan Beulich --- changes in v4: - adjusted call to using_vmx(), as it has become an inline function - added tag - description changed a bit for more clarity changes in v3: -using_vmx instead of IS_ENABLED(CONFIG_VMX) - updated description --- xen/arch/x86/traps.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index ee91fc56b1..d2af6d70d2 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -676,7 +676,6 @@ void vcpu_show_execution_state(struct vcpu *v) vcpu_pause(v); /* acceptably dangerous */ -#ifdef CONFIG_HVM /* * For VMX special care is needed: Reading some of the register state will * require VMCS accesses. Engaging foreign VMCSes involves acquiring of a @@ -684,12 +683,11 @@ void vcpu_show_execution_state(struct vcpu *v) * region. Despite this being a layering violation, engage the VMCS right * here. This then also avoids doing so several times in close succession. */ - if ( cpu_has_vmx && is_hvm_vcpu(v) ) + if ( using_vmx() && is_hvm_vcpu(v) ) { ASSERT(!in_irq()); vmx_vmcs_enter(v); } -#endif /* Prevent interleaving of output. */ flags = console_lock_recursive_irqsave(); @@ -714,10 +712,8 @@ void vcpu_show_execution_state(struct vcpu *v) console_unlock_recursive_irqrestore(flags); } -#ifdef CONFIG_HVM - if ( cpu_has_vmx && is_hvm_vcpu(v) ) + if ( using_vmx() && is_hvm_vcpu(v) ) vmx_vmcs_exit(v); -#endif vcpu_unpause(v); } From patchwork Tue Jul 9 06:00:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergiy Kibrik X-Patchwork-Id: 13727277 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id EEE59C3DA42 for ; Tue, 9 Jul 2024 06:01:16 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.755776.1164238 (Exim 4.92) (envelope-from ) id 1sR3uT-0004lU-Lw; Tue, 09 Jul 2024 06:01:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 755776.1164238; Tue, 09 Jul 2024 06:01:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3uT-0004lN-JK; Tue, 09 Jul 2024 06:01:05 +0000 Received: by outflank-mailman (input) for mailman id 755776; Tue, 09 Jul 2024 06:01:05 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3uS-0004lH-Uf for xen-devel@lists.xenproject.org; Tue, 09 Jul 2024 06:01:04 +0000 Received: from pb-smtp20.pobox.com (pb-smtp20.pobox.com [173.228.157.52]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9dbf5e01-3db8-11ef-8776-851b0ebba9a2; Tue, 09 Jul 2024 08:01:01 +0200 (CEST) Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id AE848382B5; Tue, 9 Jul 2024 02:00:59 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id A7047382B4; Tue, 9 Jul 2024 02:00:59 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from localhost (unknown [185.130.54.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id 40C5A382B3; Tue, 9 Jul 2024 02:00:56 -0400 (EDT) (envelope-from sakib@darkstar.site) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9dbf5e01-3db8-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=HOwAYjPRmMki8TMFevxWhhW05 eW/GeGVd0EhWHsG0rw=; b=OgOMcdEHMLni2UJHhjuqploQhRzpi1kzlV7zhN5Ws 1nmsFG4xBaYSKWmi9C0J7khuFcHzJYxgHdq83JqePHikXd3uYvKBeZRaF0nYC9b4 euvLXKqBJ3JklZM1FZSxMp79yyIg27HCv1YVoBpSsLRSO0h91tpHs0PRkJJkHo6A SM= From: Sergiy Kibrik To: xen-devel@lists.xenproject.org Cc: Xenia Ragiadakou , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , Xenia Ragiadakou , Sergiy Kibrik Subject: [XEN PATCH v4 08/14] x86/PV: guard svm specific functions with usinc_svm() check Date: Tue, 9 Jul 2024 09:00:52 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Pobox-Relay-ID: 9B6FE0D2-3DB8-11EF-8CCD-C38742FD603B-90055647!pb-smtp20.pobox.com From: Xenia Ragiadakou Replace cpu_has_svm check with using_svm(), so that not only SVM support in CPU is being checked at runtime, but also at build time we ensure the availability of functions svm_load_segs() and svm_load_segs_prefetch(). Since SVM depends on HVM, it can be used alone. Signed-off-by: Xenia Ragiadakou Signed-off-by: Sergiy Kibrik Acked-by: Jan Beulich --- changes in v4: - changed patch subject line - adjusted call to using_svm(), as it has become an inline function - use #ifdef CONFIG_PV - description changed a bit for more clarity - added tag changes in v3: - using_svm instead of IS_ENABLED(CONFIG_SVM) - updated description --- xen/arch/x86/domain.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index ccadfe0c9e..05cb9f7a4c 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1732,11 +1732,9 @@ static void load_segments(struct vcpu *n) if ( !(n->arch.flags & TF_kernel_mode) ) SWAP(gsb, gss); -#ifdef CONFIG_HVM - if ( cpu_has_svm && (uregs->fs | uregs->gs) <= 3 ) + if ( using_svm() && (uregs->fs | uregs->gs) <= 3 ) fs_gs_done = svm_load_segs(n->arch.pv.ldt_ents, LDT_VIRT_START(n), n->arch.pv.fs_base, gsb, gss); -#endif } if ( !fs_gs_done ) @@ -2049,9 +2047,9 @@ static void __context_switch(void) write_ptbase(n); -#if defined(CONFIG_PV) && defined(CONFIG_HVM) +#ifdef CONFIG_PV /* Prefetch the VMCB if we expect to use it later in the context switch */ - if ( cpu_has_svm && is_pv_64bit_domain(nd) && !is_idle_domain(nd) ) + if ( using_svm() && is_pv_64bit_domain(nd) && !is_idle_domain(nd) ) svm_load_segs_prefetch(); #endif From patchwork Tue Jul 9 06:02:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergiy Kibrik X-Patchwork-Id: 13727281 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 30774C2BD09 for ; Tue, 9 Jul 2024 06:03:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.755785.1164258 (Exim 4.92) (envelope-from ) id 1sR3wV-0005ru-9A; Tue, 09 Jul 2024 06:03:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 755785.1164258; Tue, 09 Jul 2024 06:03:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3wV-0005rn-5o; Tue, 09 Jul 2024 06:03:11 +0000 Received: by outflank-mailman (input) for mailman id 755785; Tue, 09 Jul 2024 06:03:09 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3wT-0005rf-QZ for xen-devel@lists.xenproject.org; Tue, 09 Jul 2024 06:03:09 +0000 Received: from pb-smtp20.pobox.com (pb-smtp20.pobox.com [173.228.157.52]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e94b1161-3db8-11ef-8776-851b0ebba9a2; Tue, 09 Jul 2024 08:03:07 +0200 (CEST) Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 5DD02382C9; Tue, 9 Jul 2024 02:03:06 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 569B1382C8; Tue, 9 Jul 2024 02:03:06 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from localhost (unknown [185.130.54.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id CBAA8382C7; Tue, 9 Jul 2024 02:03:02 -0400 (EDT) (envelope-from sakib@darkstar.site) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e94b1161-3db8-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=/ajn3Y23Ptep8PMnKlNl2X5Wf quTjK0FGfT5lFyKeSU=; b=cKDph/I4smSuMAgl6eivDKUxkZIpd0HJQoFd9wgyo YVklYn9fy2wtRlTcENA+yLICYrq1kRrcd/kCPHFRy2bo2Y/5PWzM7/TDpwRM1JC3 NCLuAC5jleS9x6SjdrXPbiu8lcxbrvMWLUBQ+5zZygqbv2Z0zw/xZhfi5oLvu0bn Ko= From: Sergiy Kibrik To: xen-devel@lists.xenproject.org Cc: Xenia Ragiadakou , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , Xenia Ragiadakou , Sergiy Kibrik Subject: [XEN PATCH v4 09/14] x86/oprofile: guard svm specific symbols with CONFIG_SVM Date: Tue, 9 Jul 2024 09:02:59 +0300 Message-Id: <3f78143694a9cb530743b438af1d7336820a7d9a.1720501197.git.Sergiy_Kibrik@epam.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Pobox-Relay-ID: E6E08580-3DB8-11EF-805F-C38742FD603B-90055647!pb-smtp20.pobox.com From: Xenia Ragiadakou The symbol svm_stgi_label is AMD-V specific so guard its usage in common code with CONFIG_SVM. Since SVM depends on HVM, it can be used alone. Also, use #ifdef instead of #if. No functional change intended. Signed-off-by: Xenia Ragiadakou Signed-off-by: Sergiy Kibrik Acked-by: Jan Beulich --- xen/arch/x86/oprofile/op_model_athlon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/arch/x86/oprofile/op_model_athlon.c b/xen/arch/x86/oprofile/op_model_athlon.c index 69fd3fcc86..a9c7b87d67 100644 --- a/xen/arch/x86/oprofile/op_model_athlon.c +++ b/xen/arch/x86/oprofile/op_model_athlon.c @@ -320,7 +320,7 @@ static int cf_check athlon_check_ctrs( struct vcpu *v = current; unsigned int const nr_ctrs = model->num_counters; -#if CONFIG_HVM +#ifdef CONFIG_SVM struct cpu_user_regs *guest_regs = guest_cpu_user_regs(); if (!guest_mode(regs) && From patchwork Tue Jul 9 06:05:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergiy Kibrik X-Patchwork-Id: 13727282 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 7859AC2BD09 for ; Tue, 9 Jul 2024 06:05:24 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.755790.1164267 (Exim 4.92) (envelope-from ) id 1sR3yU-0006QN-Gv; Tue, 09 Jul 2024 06:05:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 755790.1164267; Tue, 09 Jul 2024 06:05:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3yU-0006QG-EL; Tue, 09 Jul 2024 06:05:14 +0000 Received: by outflank-mailman (input) for mailman id 755790; Tue, 09 Jul 2024 06:05:13 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR3yT-0006QA-Dm for xen-devel@lists.xenproject.org; Tue, 09 Jul 2024 06:05:13 +0000 Received: from pb-smtp1.pobox.com (pb-smtp1.pobox.com [64.147.108.70]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3343987d-3db9-11ef-bbfb-fd08da9f4363; Tue, 09 Jul 2024 08:05:11 +0200 (CEST) Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 5709B30741; Tue, 9 Jul 2024 02:05:10 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 32CDC3073F; Tue, 9 Jul 2024 02:05:10 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from localhost (unknown [185.130.54.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id C77923073E; Tue, 9 Jul 2024 02:05:08 -0400 (EDT) (envelope-from sakib@darkstar.site) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 3343987d-3db9-11ef-bbfb-fd08da9f4363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=12DIvQiBfqGFazgmM9pTjg4zu CqQ6Op0Vdv30NEs9yM=; b=AsYC1/OeblPfeB6upecBtN3IyBi2DMwkVMDZuT8wd s3EbSTSfgadk8uISrs6yhGK5OA2FOU6nOJv/toyg3eLI+Ce5RTZu/YwWM3BK82BX B/VIkQAXumVfdFLQkn6i02qhthgSnubgc4PHSlVucB7UWTMGEeOl07Rm4sGKJlfP KM= From: Sergiy Kibrik To: xen-devel@lists.xenproject.org Cc: Sergiy Kibrik , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Paul Durrant , Jan Beulich , Stefano Stabellini , Xenia Ragiadakou , Andrew Cooper Subject: [XEN PATCH v4 10/14] x86/vmx: guard access to cpu_has_vmx_* in common code Date: Tue, 9 Jul 2024 09:05:06 +0300 Message-Id: <668355271f01681070cb15f67af1538104bfc651.1720501197.git.Sergiy_Kibrik@epam.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Pobox-Relay-ID: 31FD8298-3DB9-11EF-AE25-5B6DE52EC81B-90055647!pb-smtp1.pobox.com There're several places in common code, outside of arch/x86/hvm/vmx, where cpu_has_vmx_* get accessed without checking whether VMX supported first. These macros rely on global variables defined in vmx code, so when VMX support is disabled accesses to these variables turn into build failures. To overcome these failures, build-time check is done before accessing global variables, so that DCE would remove these variables. Signed-off-by: Sergiy Kibrik CC: Andrew Cooper CC: Jan Beulich Acked-by: Paul Durrant --- changes in v4: - use IS_ENABLED(CONFIG_VMX) instead of using_vmx changes in v3: - using_vmx instead of cpu_has_vmx - clarify description on why this change needed changes in v2: - do not touch SVM code and macros - drop vmx_ctrl_has_feature() - guard cpu_has_vmx_* macros in common code instead --- xen/arch/x86/hvm/hvm.c | 2 +- xen/arch/x86/hvm/viridian/viridian.c | 4 ++-- xen/arch/x86/include/asm/hvm/vmx/vmcs.h | 17 +++++++++++------ xen/arch/x86/traps.c | 5 +++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 057c61b4c3..be4d8ddfe7 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -5197,7 +5197,7 @@ int hvm_debug_op(struct vcpu *v, int32_t op) { case XEN_DOMCTL_DEBUG_OP_SINGLE_STEP_ON: case XEN_DOMCTL_DEBUG_OP_SINGLE_STEP_OFF: - if ( !cpu_has_monitor_trap_flag ) + if ( !IS_ENABLED(CONFIG_VMX) || !cpu_has_monitor_trap_flag ) return -EOPNOTSUPP; break; default: diff --git a/xen/arch/x86/hvm/viridian/viridian.c b/xen/arch/x86/hvm/viridian/viridian.c index 0496c52ed5..6f13ecf343 100644 --- a/xen/arch/x86/hvm/viridian/viridian.c +++ b/xen/arch/x86/hvm/viridian/viridian.c @@ -196,7 +196,7 @@ void cpuid_viridian_leaves(const struct vcpu *v, uint32_t leaf, res->a = CPUID4A_RELAX_TIMER_INT; if ( viridian_feature_mask(d) & HVMPV_hcall_remote_tlb_flush ) res->a |= CPUID4A_HCALL_REMOTE_TLB_FLUSH; - if ( !cpu_has_vmx_apic_reg_virt ) + if ( !IS_ENABLED(CONFIG_VMX) || !cpu_has_vmx_apic_reg_virt ) res->a |= CPUID4A_MSR_BASED_APIC; if ( viridian_feature_mask(d) & HVMPV_hcall_ipi ) res->a |= CPUID4A_SYNTHETIC_CLUSTER_IPI; @@ -236,7 +236,7 @@ void cpuid_viridian_leaves(const struct vcpu *v, uint32_t leaf, case 6: /* Detected and in use hardware features. */ - if ( cpu_has_vmx_virtualize_apic_accesses ) + if ( IS_ENABLED(CONFIG_VMX) && cpu_has_vmx_virtualize_apic_accesses ) res->a |= CPUID6A_APIC_OVERLAY; if ( cpu_has_vmx_msr_bitmap || (read_efer() & EFER_SVME) ) res->a |= CPUID6A_MSR_BITMAPS; diff --git a/xen/arch/x86/include/asm/hvm/vmx/vmcs.h b/xen/arch/x86/include/asm/hvm/vmx/vmcs.h index 58140af691..7421453899 100644 --- a/xen/arch/x86/include/asm/hvm/vmx/vmcs.h +++ b/xen/arch/x86/include/asm/hvm/vmx/vmcs.h @@ -306,7 +306,8 @@ extern u64 vmx_ept_vpid_cap; #define cpu_has_vmx_vnmi \ (vmx_pin_based_exec_control & PIN_BASED_VIRTUAL_NMIS) #define cpu_has_vmx_msr_bitmap \ - (vmx_cpu_based_exec_control & CPU_BASED_ACTIVATE_MSR_BITMAP) + (IS_ENABLED(CONFIG_VMX) && \ + vmx_cpu_based_exec_control & CPU_BASED_ACTIVATE_MSR_BITMAP) #define cpu_has_vmx_secondary_exec_control \ (vmx_cpu_based_exec_control & CPU_BASED_ACTIVATE_SECONDARY_CONTROLS) #define cpu_has_vmx_tertiary_exec_control \ @@ -316,7 +317,8 @@ extern u64 vmx_ept_vpid_cap; #define cpu_has_vmx_dt_exiting \ (vmx_secondary_exec_control & SECONDARY_EXEC_DESCRIPTOR_TABLE_EXITING) #define cpu_has_vmx_rdtscp \ - (vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_RDTSCP) + (IS_ENABLED(CONFIG_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_RDTSCP) #define cpu_has_vmx_vpid \ (vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_VPID) #define cpu_has_monitor_trap_flag \ @@ -333,7 +335,8 @@ extern u64 vmx_ept_vpid_cap; #define cpu_has_vmx_ple \ (vmx_secondary_exec_control & SECONDARY_EXEC_PAUSE_LOOP_EXITING) #define cpu_has_vmx_invpcid \ - (vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_INVPCID) + (IS_ENABLED(CONFIG_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_INVPCID) #define cpu_has_vmx_apic_reg_virt \ (vmx_secondary_exec_control & SECONDARY_EXEC_APIC_REGISTER_VIRT) #define cpu_has_vmx_virtual_intr_delivery \ @@ -347,14 +350,16 @@ extern u64 vmx_ept_vpid_cap; #define cpu_has_vmx_vmfunc \ (vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_VM_FUNCTIONS) #define cpu_has_vmx_virt_exceptions \ - (vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS) + (IS_ENABLED(CONFIG_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS) #define cpu_has_vmx_pml \ (vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_PML) #define cpu_has_vmx_mpx \ - ((vmx_vmexit_control & VM_EXIT_CLEAR_BNDCFGS) && \ + (IS_ENABLED(CONFIG_VMX) && (vmx_vmexit_control & VM_EXIT_CLEAR_BNDCFGS) && \ (vmx_vmentry_control & VM_ENTRY_LOAD_BNDCFGS)) #define cpu_has_vmx_xsaves \ - (vmx_secondary_exec_control & SECONDARY_EXEC_XSAVES) + (IS_ENABLED(CONFIG_VMX) && \ + vmx_secondary_exec_control & SECONDARY_EXEC_XSAVES) #define cpu_has_vmx_tsc_scaling \ (vmx_secondary_exec_control & SECONDARY_EXEC_TSC_SCALING) #define cpu_has_vmx_bus_lock_detection \ diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index d2af6d70d2..27115712a4 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -1130,7 +1130,7 @@ void cpuid_hypervisor_leaves(const struct vcpu *v, uint32_t leaf, if ( !is_hvm_domain(d) || subleaf != 0 ) break; - if ( cpu_has_vmx_apic_reg_virt ) + if ( IS_ENABLED(CONFIG_VMX) && cpu_has_vmx_apic_reg_virt ) res->a |= XEN_HVM_CPUID_APIC_ACCESS_VIRT; /* @@ -1139,7 +1139,8 @@ void cpuid_hypervisor_leaves(const struct vcpu *v, uint32_t leaf, * and wrmsr in the guest will run without VMEXITs (see * vmx_vlapic_msr_changed()). */ - if ( cpu_has_vmx_virtualize_x2apic_mode && + if ( IS_ENABLED(CONFIG_VMX) && + cpu_has_vmx_virtualize_x2apic_mode && cpu_has_vmx_apic_reg_virt && cpu_has_vmx_virtual_intr_delivery ) res->a |= XEN_HVM_CPUID_X2APIC_VIRT; From patchwork Tue Jul 9 06:07:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergiy Kibrik X-Patchwork-Id: 13727289 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id CCCAEC3DA42 for ; Tue, 9 Jul 2024 06:07:37 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.755802.1164277 (Exim 4.92) (envelope-from ) id 1sR40Y-0007Iw-ST; Tue, 09 Jul 2024 06:07:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 755802.1164277; Tue, 09 Jul 2024 06:07:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR40Y-0007Ip-Pk; Tue, 09 Jul 2024 06:07:22 +0000 Received: by outflank-mailman (input) for mailman id 755802; Tue, 09 Jul 2024 06:07:21 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR40X-0007IQ-0t for xen-devel@lists.xenproject.org; Tue, 09 Jul 2024 06:07:21 +0000 Received: from pb-smtp20.pobox.com (pb-smtp20.pobox.com [173.228.157.52]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7ed20419-3db9-11ef-bbfb-fd08da9f4363; Tue, 09 Jul 2024 08:07:19 +0200 (CEST) Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 0F0EC382F9; Tue, 9 Jul 2024 02:07:17 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 06B85382F8; Tue, 9 Jul 2024 02:07:17 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from localhost (unknown [185.130.54.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id 95033382F7; Tue, 9 Jul 2024 02:07:13 -0400 (EDT) (envelope-from sakib@darkstar.site) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7ed20419-3db9-11ef-bbfb-fd08da9f4363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=9MUbn1fRlgry16ZYW2HGE8mSd PK82agq4/JnQRvpvls=; b=UkNSmdVD/CbmJRUkXzQTF2PhCdlKnW/vjFYnyQRst Vcse+Qx8VTrRFn2f+T/yriogwO3gEg/n7Nfh/co/VEbcN/v5+8a25+XOMALVEkTx e2JwBXuN9zfnMwmHkFhzqBgiEhqEAzKIJt0gTkfzLxCmritnAUOB7E9QY7H84sQI PA= From: Sergiy Kibrik To: xen-devel@lists.xenproject.org Cc: Sergiy Kibrik , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , Xenia Ragiadakou Subject: [XEN PATCH v4 11/14] x86/vpmu: guard calls to vmx/svm functions Date: Tue, 9 Jul 2024 09:07:10 +0300 Message-Id: <81999eb47b590afe3b269c33f7d166c9882cafdc.1720501197.git.Sergiy_Kibrik@epam.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Pobox-Relay-ID: 7C59892C-3DB9-11EF-92DA-C38742FD603B-90055647!pb-smtp20.pobox.com If VMX/SVM disabled in the build, we may still want to have vPMU drivers for PV guests. Yet in such case before using VMX/SVM features and functions we have to explicitly check if they're available in the build. For this purpose (and also not to complicate conditionals) two helpers introduced -- is_{vmx,svm}_vcpu(v) that check both HVM & VMX/SVM conditions at the same time, and they replace is_hvm_vcpu(v) macro where needed. Signed-off-by: Sergiy Kibrik --- changes in v4: - use IS_ENABLED(CONFIG_{VMX,SVM}) instead of using_{vmx,svm} - fix typo changes in v3: - introduced macro is_{vmx,svm}_vcpu(v) - changed description - reordered patch, do not modify conditionals w/ cpu_has_vmx_msr_bitmap check --- xen/arch/x86/cpu/vpmu_amd.c | 9 +++++---- xen/arch/x86/cpu/vpmu_intel.c | 16 +++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/cpu/vpmu_amd.c b/xen/arch/x86/cpu/vpmu_amd.c index 97e6315bd9..977c2f1e73 100644 --- a/xen/arch/x86/cpu/vpmu_amd.c +++ b/xen/arch/x86/cpu/vpmu_amd.c @@ -27,6 +27,7 @@ #define is_pmu_enabled(msr) ((msr) & (1ULL << MSR_F10H_EVNTSEL_EN_SHIFT)) #define set_guest_mode(msr) ((msr) |= (1ULL << MSR_F10H_EVNTSEL_GO_SHIFT)) #define is_overflowed(msr) (!((msr) & (1ULL << (MSR_F10H_COUNTER_LENGTH - 1)))) +#define is_svm_vcpu(v) (IS_ENABLED(CONFIG_SVM) && is_hvm_vcpu(v)) static unsigned int __read_mostly num_counters; static const u32 __read_mostly *counters; @@ -289,7 +290,7 @@ static int cf_check amd_vpmu_save(struct vcpu *v, bool to_guest) context_save(v); - if ( !vpmu_is_set(vpmu, VPMU_RUNNING) && is_hvm_vcpu(v) && + if ( !vpmu_is_set(vpmu, VPMU_RUNNING) && is_svm_vcpu(v) && is_msr_bitmap_on(vpmu) ) amd_vpmu_unset_msr_bitmap(v); @@ -363,7 +364,7 @@ static int cf_check amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) return 0; vpmu_set(vpmu, VPMU_RUNNING); - if ( is_hvm_vcpu(v) && is_msr_bitmap_on(vpmu) ) + if ( is_svm_vcpu(v) && is_msr_bitmap_on(vpmu) ) amd_vpmu_set_msr_bitmap(v); } @@ -372,7 +373,7 @@ static int cf_check amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) (is_pmu_enabled(msr_content) == 0) && vpmu_is_set(vpmu, VPMU_RUNNING) ) { vpmu_reset(vpmu, VPMU_RUNNING); - if ( is_hvm_vcpu(v) && is_msr_bitmap_on(vpmu) ) + if ( is_svm_vcpu(v) && is_msr_bitmap_on(vpmu) ) amd_vpmu_unset_msr_bitmap(v); release_pmu_ownership(PMU_OWNER_HVM); } @@ -415,7 +416,7 @@ static void cf_check amd_vpmu_destroy(struct vcpu *v) { struct vpmu_struct *vpmu = vcpu_vpmu(v); - if ( is_hvm_vcpu(v) && is_msr_bitmap_on(vpmu) ) + if ( is_svm_vcpu(v) && is_msr_bitmap_on(vpmu) ) amd_vpmu_unset_msr_bitmap(v); xfree(vpmu->context); diff --git a/xen/arch/x86/cpu/vpmu_intel.c b/xen/arch/x86/cpu/vpmu_intel.c index cd414165df..db35d22aaf 100644 --- a/xen/arch/x86/cpu/vpmu_intel.c +++ b/xen/arch/x86/cpu/vpmu_intel.c @@ -54,6 +54,8 @@ #define MSR_PMC_ALIAS_MASK (~(MSR_IA32_PERFCTR0 ^ MSR_IA32_A_PERFCTR0)) static bool __read_mostly full_width_write; +#define is_vmx_vcpu(v) (IS_ENABLED(CONFIG_VMX) && is_hvm_vcpu(v)) + /* * MSR_CORE_PERF_FIXED_CTR_CTRL contains the configuration of all fixed * counters. 4 bits for every counter. @@ -269,7 +271,7 @@ static inline void __core2_vpmu_save(struct vcpu *v) if ( !is_hvm_vcpu(v) ) rdmsrl(MSR_CORE_PERF_GLOBAL_STATUS, core2_vpmu_cxt->global_status); /* Save MSR to private context to make it fork-friendly */ - else if ( mem_sharing_enabled(v->domain) ) + else if ( is_vmx_vcpu(v) && mem_sharing_enabled(v->domain) ) vmx_read_guest_msr(v, MSR_CORE_PERF_GLOBAL_CTRL, &core2_vpmu_cxt->global_ctrl); } @@ -333,7 +335,7 @@ static inline void __core2_vpmu_load(struct vcpu *v) wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, core2_vpmu_cxt->global_ctrl); } /* Restore MSR from context when used with a fork */ - else if ( mem_sharing_is_fork(v->domain) ) + else if ( is_vmx_vcpu(v) && mem_sharing_is_fork(v->domain) ) vmx_write_guest_msr(v, MSR_CORE_PERF_GLOBAL_CTRL, core2_vpmu_cxt->global_ctrl); } @@ -442,7 +444,7 @@ static int cf_check core2_vpmu_alloc_resource(struct vcpu *v) if ( !acquire_pmu_ownership(PMU_OWNER_HVM) ) return 0; - if ( is_hvm_vcpu(v) ) + if ( is_vmx_vcpu(v) ) { if ( vmx_add_host_load_msr(v, MSR_CORE_PERF_GLOBAL_CTRL, 0) ) goto out_err; @@ -584,7 +586,7 @@ static int cf_check core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) if ( msr_content & fixed_ctrl_mask ) return -EINVAL; - if ( is_hvm_vcpu(v) ) + if ( is_vmx_vcpu(v) ) vmx_read_guest_msr(v, MSR_CORE_PERF_GLOBAL_CTRL, &core2_vpmu_cxt->global_ctrl); else @@ -653,7 +655,7 @@ static int cf_check core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) if ( blocked ) return -EINVAL; - if ( is_hvm_vcpu(v) ) + if ( is_vmx_vcpu(v) ) vmx_read_guest_msr(v, MSR_CORE_PERF_GLOBAL_CTRL, &core2_vpmu_cxt->global_ctrl); else @@ -672,7 +674,7 @@ static int cf_check core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content) wrmsrl(msr, msr_content); else { - if ( is_hvm_vcpu(v) ) + if ( is_vmx_vcpu(v) ) vmx_write_guest_msr(v, MSR_CORE_PERF_GLOBAL_CTRL, msr_content); else wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, msr_content); @@ -706,7 +708,7 @@ static int cf_check core2_vpmu_do_rdmsr(unsigned int msr, uint64_t *msr_content) *msr_content = core2_vpmu_cxt->global_status; break; case MSR_CORE_PERF_GLOBAL_CTRL: - if ( is_hvm_vcpu(v) ) + if ( is_vmx_vcpu(v) ) vmx_read_guest_msr(v, MSR_CORE_PERF_GLOBAL_CTRL, msr_content); else rdmsrl(MSR_CORE_PERF_GLOBAL_CTRL, *msr_content); From patchwork Tue Jul 9 06:09:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergiy Kibrik X-Patchwork-Id: 13727290 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 0B919C2BD09 for ; Tue, 9 Jul 2024 06:09:33 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.755809.1164288 (Exim 4.92) (envelope-from ) id 1sR42W-0008Nj-BM; Tue, 09 Jul 2024 06:09:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 755809.1164288; Tue, 09 Jul 2024 06:09:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR42W-0008Nc-7Z; Tue, 09 Jul 2024 06:09:24 +0000 Received: by outflank-mailman (input) for mailman id 755809; Tue, 09 Jul 2024 06:09:23 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR42V-0008NW-1A for xen-devel@lists.xenproject.org; Tue, 09 Jul 2024 06:09:23 +0000 Received: from pb-smtp2.pobox.com (pb-smtp2.pobox.com [64.147.108.71]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c7fd9d1c-3db9-11ef-8776-851b0ebba9a2; Tue, 09 Jul 2024 08:09:21 +0200 (CEST) Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 33CD127200; Tue, 9 Jul 2024 02:09:20 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 2AABD271FF; Tue, 9 Jul 2024 02:09:20 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from localhost (unknown [185.130.54.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id 3E872271FC; Tue, 9 Jul 2024 02:09:18 -0400 (EDT) (envelope-from sakib@darkstar.site) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c7fd9d1c-3db9-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=WAtXH3fP6tKdqS2avDvIWj8s3 ooKivAC2EaiAkYKfEA=; b=OWWU9QInf4b8Kqejm9TFMCexdIqGNT969Y5KQ1m76 dkw+ma1Z1W27lerK4aM75tnyr7ETC2MeQ029RDldUFk5LwOVAUhLTwmqa2Ond4lb cRWXA1fpymF53jzL00UQD7wLLfAlbMBrhWxh8bEymDzQXpsUrMhYvoVu1Zs6jkHx JU= From: Sergiy Kibrik To: xen-devel@lists.xenproject.org Cc: Xenia Ragiadakou , Stefano Stabellini , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Jan Beulich , Xenia Ragiadakou , Sergiy Kibrik , Julien Grall Subject: [XEN PATCH v4 12/14] x86/ioreq: guard VIO_realmode_completion with CONFIG_VMX Date: Tue, 9 Jul 2024 09:09:16 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Pobox-Relay-ID: C73E9324-3DB9-11EF-A124-965B910A682E-90055647!pb-smtp2.pobox.com From: Xenia Ragiadakou VIO_realmode_completion is specific to vmx realmode and thus the function arch_vcpu_ioreq_completion() has actual handling code only in VMX-enabled build, as for the rest x86 and ARM build configurations it is basically a stub. So these stubs can be avoided by moving VIO_realmode_completion handler's code under CONFIG_VMX and then ARM stub can be removed completely. Signed-off-by: Xenia Ragiadakou Signed-off-by: Sergiy Kibrik CC: Julien Grall CC: Jan Beulich --- changes in v4: - move whole arch_vcpu_ioreq_completion() under CONFIG_VMX and remove ARM's variant of this handler, as Julien suggested changes in v1: - put VIO_realmode_completion enum under #ifdef CONFIG_VMX --- xen/arch/arm/ioreq.c | 6 ------ xen/arch/x86/hvm/ioreq.c | 2 ++ xen/arch/x86/include/asm/hvm/ioreq.h | 5 +++++ xen/common/ioreq.c | 5 ++++- xen/include/xen/ioreq.h | 1 - 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/ioreq.c b/xen/arch/arm/ioreq.c index 5df755b48b..2e829d2e7f 100644 --- a/xen/arch/arm/ioreq.c +++ b/xen/arch/arm/ioreq.c @@ -135,12 +135,6 @@ bool arch_ioreq_complete_mmio(void) return false; } -bool arch_vcpu_ioreq_completion(enum vio_completion completion) -{ - ASSERT_UNREACHABLE(); - return true; -} - /* * The "legacy" mechanism of mapping magic pages for the IOREQ servers * is x86 specific, so the following hooks don't need to be implemented on Arm: diff --git a/xen/arch/x86/hvm/ioreq.c b/xen/arch/x86/hvm/ioreq.c index 4eb7a70182..0406630dc8 100644 --- a/xen/arch/x86/hvm/ioreq.c +++ b/xen/arch/x86/hvm/ioreq.c @@ -29,6 +29,7 @@ bool arch_ioreq_complete_mmio(void) return handle_mmio(); } +#ifdef CONFIG_VMX bool arch_vcpu_ioreq_completion(enum vio_completion completion) { switch ( completion ) @@ -51,6 +52,7 @@ bool arch_vcpu_ioreq_completion(enum vio_completion completion) return true; } +#endif static gfn_t hvm_alloc_legacy_ioreq_gfn(struct ioreq_server *s) { diff --git a/xen/arch/x86/include/asm/hvm/ioreq.h b/xen/arch/x86/include/asm/hvm/ioreq.h index 84be14fd08..c5f16a1e4a 100644 --- a/xen/arch/x86/include/asm/hvm/ioreq.h +++ b/xen/arch/x86/include/asm/hvm/ioreq.h @@ -13,6 +13,11 @@ #define IOREQ_STATUS_UNHANDLED X86EMUL_UNHANDLEABLE #define IOREQ_STATUS_RETRY X86EMUL_RETRY +#ifdef CONFIG_VMX +bool arch_vcpu_ioreq_completion(enum vio_completion completion); +#define arch_vcpu_ioreq_completion +#endif + #endif /* __ASM_X86_HVM_IOREQ_H__ */ /* diff --git a/xen/common/ioreq.c b/xen/common/ioreq.c index 1257a3d972..10fe932a7e 100644 --- a/xen/common/ioreq.c +++ b/xen/common/ioreq.c @@ -242,9 +242,12 @@ bool vcpu_ioreq_handle_completion(struct vcpu *v) res = handle_pio(vio->req.addr, vio->req.size, vio->req.dir); break; - default: +#ifdef arch_vcpu_ioreq_completion res = arch_vcpu_ioreq_completion(completion); +#else + ASSERT_UNREACHABLE(); +#endif break; } diff --git a/xen/include/xen/ioreq.h b/xen/include/xen/ioreq.h index cd399adf17..22fb9ba7b0 100644 --- a/xen/include/xen/ioreq.h +++ b/xen/include/xen/ioreq.h @@ -111,7 +111,6 @@ void ioreq_domain_init(struct domain *d); int ioreq_server_dm_op(struct xen_dm_op *op, struct domain *d, bool *const_op); bool arch_ioreq_complete_mmio(void); -bool arch_vcpu_ioreq_completion(enum vio_completion completion); int arch_ioreq_server_map_pages(struct ioreq_server *s); void arch_ioreq_server_unmap_pages(struct ioreq_server *s); void arch_ioreq_server_enable(struct ioreq_server *s); From patchwork Tue Jul 9 06:11:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergiy Kibrik X-Patchwork-Id: 13727291 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 25F54C2BD09 for ; Tue, 9 Jul 2024 06:11:39 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.755813.1164297 (Exim 4.92) (envelope-from ) id 1sR44X-0001np-MD; Tue, 09 Jul 2024 06:11:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 755813.1164297; Tue, 09 Jul 2024 06:11:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR44X-0001ni-Jk; Tue, 09 Jul 2024 06:11:29 +0000 Received: by outflank-mailman (input) for mailman id 755813; Tue, 09 Jul 2024 06:11:28 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR44W-0001nZ-DL for xen-devel@lists.xenproject.org; Tue, 09 Jul 2024 06:11:28 +0000 Received: from pb-smtp2.pobox.com (pb-smtp2.pobox.com [64.147.108.71]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 12cb4bbf-3dba-11ef-8776-851b0ebba9a2; Tue, 09 Jul 2024 08:11:26 +0200 (CEST) Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id B7D0427215; Tue, 9 Jul 2024 02:11:25 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id AF39527214; Tue, 9 Jul 2024 02:11:25 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from localhost (unknown [185.130.54.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id CFCA727213; Tue, 9 Jul 2024 02:11:24 -0400 (EDT) (envelope-from sakib@darkstar.site) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 12cb4bbf-3dba-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=J28BmUC9XkwRwgOIlqfahU9nc wSpzZpKk8zf3xzLqjA=; b=iGFicwm/Q1Wh+dUhWeptMpNgGF+1/z8v9wTBS1seV TZNrt+HcJRbVKqH+GrzZBuP6xmEqUfY5WVOtsbzzB8JrVG1y1hgJN/chOpcl4MZJ SkSqTvHS8ZKL9G1SQ+2e1zqDv1ASWlsHa49sdEI669OO0QtkUf0BlotnkLzF48fL tQ= From: Sergiy Kibrik To: xen-devel@lists.xenproject.org Cc: Sergiy Kibrik , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , Xenia Ragiadakou Subject: [XEN PATCH v4 13/14] x86/vmx: replace CONFIG_HVM with CONFIG_VMX in vmx.h Date: Tue, 9 Jul 2024 09:11:20 +0300 Message-Id: <75c4f38c1d598fa751a75b7c5b11ce2e5b08df6d.1720501197.git.Sergiy_Kibrik@epam.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Pobox-Relay-ID: 121A3254-3DBA-11EF-B89C-965B910A682E-90055647!pb-smtp2.pobox.com As now we got a separate config option for VMX which itself depends on CONFIG_HVM, we need to use it to provide vmx_pi_hooks_{assign,deassign} stubs for case when VMX is disabled while HVM is enabled. Signed-off-by: Sergiy Kibrik Acked-by: Jan Beulich --- changes in v4: - added tag changes in v3: - use CONFIG_VMX instead of CONFIG_HVM to provide stubs, instead of guarding calls to vmx_pi_hooks_{assign,deassign} in iommu/vt-d code --- xen/arch/x86/include/asm/hvm/vmx/vmx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/arch/x86/include/asm/hvm/vmx/vmx.h b/xen/arch/x86/include/asm/hvm/vmx/vmx.h index 1489dd05c2..025bec2321 100644 --- a/xen/arch/x86/include/asm/hvm/vmx/vmx.h +++ b/xen/arch/x86/include/asm/hvm/vmx/vmx.h @@ -599,7 +599,7 @@ void vmx_pi_desc_fixup(unsigned int cpu); void vmx_sync_exit_bitmap(struct vcpu *v); -#ifdef CONFIG_HVM +#ifdef CONFIG_VMX void vmx_pi_hooks_assign(struct domain *d); void vmx_pi_hooks_deassign(struct domain *d); #else From patchwork Tue Jul 9 06:13:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergiy Kibrik X-Patchwork-Id: 13727294 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 3B300C2BD09 for ; Tue, 9 Jul 2024 06:13:45 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.755818.1164307 (Exim 4.92) (envelope-from ) id 1sR46Y-0002Mx-1w; Tue, 09 Jul 2024 06:13:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 755818.1164307; Tue, 09 Jul 2024 06:13:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR46X-0002Mq-Vh; Tue, 09 Jul 2024 06:13:33 +0000 Received: by outflank-mailman (input) for mailman id 755818; Tue, 09 Jul 2024 06:13:32 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sR46W-0002Mj-D5 for xen-devel@lists.xenproject.org; Tue, 09 Jul 2024 06:13:32 +0000 Received: from pb-smtp2.pobox.com (pb-smtp2.pobox.com [64.147.108.71]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5c861079-3dba-11ef-bbfb-fd08da9f4363; Tue, 09 Jul 2024 08:13:31 +0200 (CEST) Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 3E96227243; Tue, 9 Jul 2024 02:13:29 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 3688E27242; Tue, 9 Jul 2024 02:13:29 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from localhost (unknown [185.130.54.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id 6A53527241; Tue, 9 Jul 2024 02:13:28 -0400 (EDT) (envelope-from sakib@darkstar.site) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5c861079-3dba-11ef-bbfb-fd08da9f4363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=JHgRlQ2mOAVaV36q/DwoXTgbm MjsvlXARfcG6GpvdPs=; b=ABDKpP08RVJUTSKPO/M+QuO4dPVccBbAhNMmiHMaF ns8XXFCmHKIGgRQGMR4rQdNy0hon70BknNoRGa3zVv5cJb8SUdvyIuEMRE9v7fec SQ7PCehaoIsz5M9IOul22pGxTGWItD+jCPycg8g6Uj7eNpsIbq4m8fVSMPDytUI+ Lg= From: Sergiy Kibrik To: xen-devel@lists.xenproject.org Cc: Xenia Ragiadakou , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , Xenia Ragiadakou , Sergiy Kibrik Subject: [XEN PATCH v4 14/14] x86/hvm: make AMD-V and Intel VT-x support configurable Date: Tue, 9 Jul 2024 09:13:25 +0300 Message-Id: <77b83b71a9f759fcf925675b36fcd3f58e06fff1.1720501197.git.Sergiy_Kibrik@epam.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Pobox-Relay-ID: 5BC43260-3DBA-11EF-8A32-965B910A682E-90055647!pb-smtp2.pobox.com From: Xenia Ragiadakou Provide the user with configuration control over the cpu virtualization support in Xen by making SVM and VMX options user selectable. To preserve the current default behavior, both options depend on HVM and default to value of HVM. To prevent users from unknowingly disabling virtualization support, make the controls user selectable only if EXPERT is enabled. No functional change intended. Signed-off-by: Xenia Ragiadakou Signed-off-by: Sergiy Kibrik Reviewed-by: Stefano Stabellini Acked-by: Jan Beulich --- changes in v3: - only tags added changes in v2: - remove dependency of build options IOMMU/AMD_IOMMU on VMX/SVM options --- xen/arch/x86/Kconfig | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 4a35c43dc5..dbee7c2efb 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -123,10 +123,24 @@ config HVM If unsure, say Y. config SVM - def_bool HVM + bool "AMD-V" if EXPERT + depends on HVM + default HVM + help + Enables virtual machine extensions on platforms that implement the + AMD Virtualization Technology (AMD-V). + If your system includes a processor with AMD-V support, say Y. + If in doubt, say Y. config VMX - def_bool HVM + bool "Intel VT-x" if EXPERT + depends on HVM + default HVM + help + Enables virtual machine extensions on platforms that implement the + Intel Virtualization Technology (Intel VT-x). + If your system includes a processor with Intel VT-x support, say Y. + If in doubt, say Y. config XEN_SHSTK bool "Supervisor Shadow Stacks"