From nobody Mon Nov 25 08:00:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=quarantine dis=quarantine) header.from=epam.com ARC-Seal: i=1; a=rsa-sha256; t=1722334868; cv=none; d=zohomail.com; s=zohoarc; b=HMnq5djGJW1xWyQ4F/yLGoyV4ONppxZZFTiJpHTASUQ4ggwpebHnfWzMVgAx9H6LPq2Hk7UT0xgi1FLjrAihXUM/kiJ/iWQu6w6/wwo+S37GipSDRc0MIG2CNfsWbNbCbyPHWt/6kRyHzS+bPy5vcLX0To/5ee9BHTc4ZeChE2o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722334868; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yIzS4gQFrVNKCHChQ53SrTF1e/wD1F2aeioImXEhkLQ=; b=d8LqNK+46GGuZAoOd//sUJkc42qQKyFx9UBhFIjuW9OFJskBOvGtxOJ/Ui3Nb/m/oSiJodjz2UYFGLuCV65pmhiBc5cUq889xieVrjWo5LQSObOXzqmWpegLM+e7j6NIqUpl56u8yXUDgTFkHpDpaRSgUKDwnmnJYVIo6sUUUVk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=quarantine dis=quarantine) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 172233486886978.98606347584018; Tue, 30 Jul 2024 03:21:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.767468.1178122 (Exim 4.92) (envelope-from ) id 1sYjyB-0002vq-Mf; Tue, 30 Jul 2024 10:20:39 +0000 Received: by outflank-mailman (output) from mailman id 767468.1178122; Tue, 30 Jul 2024 10:20: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 1sYjyB-0002vj-Jr; Tue, 30 Jul 2024 10:20:39 +0000 Received: by outflank-mailman (input) for mailman id 767468; Tue, 30 Jul 2024 10:20: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 1sYjyA-0002vY-Gy for xen-devel@lists.xenproject.org; Tue, 30 Jul 2024 10:20:38 +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 5bf26ede-4e5d-11ef-8776-851b0ebba9a2; Tue, 30 Jul 2024 12:20:36 +0200 (CEST) Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id BEE613543E; Tue, 30 Jul 2024 06:20:34 -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 AA39C3543D; Tue, 30 Jul 2024 06:20:34 -0400 (EDT) (envelope-from sakib@darkstar.site) Received: from localhost (unknown [185.130.54.90]) (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 E6F173543C; Tue, 30 Jul 2024 06:20:29 -0400 (EDT) (envelope-from sakib@darkstar.site) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 5bf26ede-4e5d-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=Ily8J/O+RwpKuEMEVWmpbQY+A 5ZLNIXdklAbdyftYqw=; b=gPvbyx6TzGtHVI55TGXvS4g+slOmVkqyoJJye03ro R2SwrVzrP2cmh6YepESBFyr45FEHtwuYWadfJgpgjIzPt9WDggLlI/1aJdcIiFP9 HWvHiwjVOoyt5Fv9D3uS92QdngkesfsPCZFR5xScyCRTN9xfpOnb/pTY7a/S6UUc z4= From: Sergiy Kibrik To: xen-devel@lists.xenproject.org Cc: Sergiy Kibrik , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini , Xenia Ragiadakou , Tamas K Lengyel Subject: [XEN PATCH v5 03/13] x86: introduce CONFIG_ALTP2M Kconfig option Date: Tue, 30 Jul 2024 13:20:26 +0300 Message-Id: <93cb9a86c76a8d7cb24df916a4049b92bfb24459.1722333634.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: 58BF2B84-4E5D-11EF-A1B7-92D9AF168FA5-90055647!pb-smtp20.pobox.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @pobox.com) X-ZM-MESSAGEID: 1722334870299116600 Content-Type: text/plain; charset="utf-8" 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=3Dy, 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 successful= ly (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 Reviewed-by: Jan Beulich CC: Tamas K Lengyel CC: Stefano Stabellini --- changes in v5: - change kconfig option name VMX -> INTEL_VMX changes in v4: - move static inline stub for p2m_altp2m_check() from under CONFIG_HVM und= er CONFIG_ALTP2M - keep AP2MGET_prepopulate/AP2MGET_query under CONFIG_ALTP2M as Jan sugges= ted changes in v3: - added help text - use conditional prompt depending on EXPERT=3Dy - 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 --- 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 fa5405e0d3..cd81fd1675 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. =20 +config ALTP2M + bool "Alternate P2M support" if EXPERT + default y + depends on INTEL_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 =20 source "common/Kconfig" diff --git a/xen/arch/x86/include/asm/altp2m.h b/xen/arch/x86/include/asm/a= ltp2m.h index e5e59cbd68..c57a8c5588 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 =20 -#ifdef CONFIG_HVM +#ifdef CONFIG_ALTP2M =20 #include #include /* for struct vcpu, struct domain */ @@ -39,6 +39,9 @@ static inline bool altp2m_active(const struct domain *d) =20 /* Only declaration is needed. DCE will optimise it out when linking. */ uint16_t altp2m_vcpu_idx(const struct vcpu *v); +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); =20 #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; } =20 /* Returns true if we have the minimum hardware requirements for nested vi= rt */ 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)); } =20 -#ifdef CONFIG_HVM +#ifdef CONFIG_ALTP2M #define AP2MGET_prepopulate true #define AP2MGET_query false =20 @@ -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 =20 /* Init the datastructures for later use by the p2m code */ @@ -914,9 +924,6 @@ static inline bool p2m_set_altp2m(struct vcpu *v, unsig= ned int idx) /* Switch alternate p2m for a single vcpu */ bool p2m_switch_vcpu_altp2m_by_id(struct vcpu *v, unsigned int idx); =20 -/* 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); =20 @@ -952,9 +959,15 @@ int p2m_set_altp2m_view_visibility(struct domain *d, u= nsigned 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 */ =20 +#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 52c5abdfee..0345388359 100644 --- a/xen/arch/x86/mm/Makefile +++ b/xen/arch/x86/mm/Makefile @@ -1,7 +1,7 @@ obj-y +=3D shadow/ obj-$(CONFIG_HVM) +=3D hap/ =20 -obj-$(CONFIG_HVM) +=3D altp2m.o +obj-$(CONFIG_ALTP2M) +=3D altp2m.o obj-$(CONFIG_HVM) +=3D guest_walk_2.o guest_walk_3.o guest_walk_4.o obj-$(CONFIG_SHADOW_PAGING) +=3D guest_walk_4.o obj-$(CONFIG_MEM_ACCESS) +=3D mem_access.o --=20 2.25.1