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 271BFF5A8BB for ; Mon, 20 Apr 2026 20:26:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1286513.1567703 (Exim 4.92) (envelope-from ) id 1wEvBl-0008Gl-OM; Mon, 20 Apr 2026 20:25:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1286513.1567703; Mon, 20 Apr 2026 20:25: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 1wEvBj-00088v-E1; Mon, 20 Apr 2026 20:25:47 +0000 Received: by outflank-mailman (input) for mailman id 1286513; Mon, 20 Apr 2026 19:55:09 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wEui5-0006VB-U5 for xen-devel@lists.xenproject.org; Mon, 20 Apr 2026 19:55:09 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wEui5-00C0mN-B4 for xen-devel@lists.xenproject.org; Mon, 20 Apr 2026 21:55:09 +0200 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69e6849d-5cb7-0a2a0a5109dd-0a2a450bd69e-2 for ; Mon, 20 Apr 2026 21:55:09 +0200 Received: from [34.202.193.197] (helo=sendmail.purelymail.com) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 69e683ab-212f-0a2a450b0019-22cac1c5c2e8-3 for ; Mon, 20 Apr 2026 21:51:08 +0200 Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id -306608446; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Mon, 20 Apr 2026 19:50:58 +0000 (UTC) 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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=purelymail1 header.d=purelymail.com header.i="@purelymail.com" header.h="Feedback-ID:Received:From:To:Subject:Date" DKIM-Signature: a=rsa-sha256; b=G8Au/F7w0kr3yWBN493bKoUzi1aJp5ehASYi4BlnUh6gTILN9XNytRgGapOi7MBFApd8IY5pvk4fGWY7FmNiOdKTP3NFVO+EVEVwOKjasT+Pi5mMEkubMSLcxQJj/QtiILUpuLEtAiQK/+wab7YXBiO7jPtJfWQ95xa5JzwwrkiIhxOjhmFPSFMgRE5R3R+TbmS35xpSYX5JTAXMoQSIO2ZL3QsYCw/RVEoau4CHHuV8Ely0Q1pwwo36pTfdPYZWCJUy/yxpWYpfiqoaP0bIhU6HY6WbbejJpCdA5neGJGo2D2WCi3SRI51XOBnov+kYae9EDSlUHk+A0KRdFT597A==; s=purelymail1; d=purelymail.com; v=1; bh=3WaQvrna8zsFCyA45arxMyrce2HZKSIAvzQk5fZ8kuY=; h=Feedback-ID:Received:From:To:Subject:Date; Feedback-ID: 685805:22403:null:purelymail X-Pm-Original-To: xen-devel@lists.xenproject.org From: Rose.Spangler@purelymail.com To: xen-devel@lists.xenproject.org Cc: Rose Spangler , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Michal Orzel , Julien Grall , Stefano Stabellini Subject: [RFC PATCH v6 24/43] altp2m: Move altp2m_{get,set}_altp2m to common code Date: Mon, 20 Apr 2026 15:50:23 -0400 Message-Id: <20260420195042.207624-25-Rose.Spangler@purelymail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260420195042.207624-1-Rose.Spangler@purelymail.com> References: <20260420195042.207624-1-Rose.Spangler@purelymail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by Purelymail Content-Type: text/plain; charset=UTF-8 X-purgate-ID: tlsNG-42698a/1776714668-246B7F3B-BCC1441B/13/0 X-purgate-type: clean X-purgate-size: 5177 From: Rose Spangler This commit moves the altp2m_get_altp2m and altp2m_set_altp2m functions to the common code. This make sit possible to use them in other common routines (namely, altp2m_vcpu_{initialise,destroy}). This commit contains only code movement, and no change in functionality is intended. This is commit 1/4 of the altp2m_{get,set}_altp2m phase. Signed-off-by: Rose Spangler --- v6: Introduced this patch. --- xen/arch/x86/include/asm/altp2m.h | 35 ------------------------- xen/arch/x86/include/asm/domain.h | 2 -- xen/common/altp2m.c | 1 - xen/include/xen/altp2m.h | 43 +++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 38 deletions(-) diff --git a/xen/arch/x86/include/asm/altp2m.h b/xen/arch/x86/include/asm/a= ltp2m.h index 13017525a62f..a1b078783b3e 100644 --- a/xen/arch/x86/include/asm/altp2m.h +++ b/xen/arch/x86/include/asm/altp2m.h @@ -64,39 +64,6 @@ static inline uint16_t altp2m_vcpu_idx(const struct vcpu= *v) * Alternate p2m: shadow p2m tables used for alternate memory views */ =20 -/* get current alternate p2m table */ -static inline struct p2m_domain *altp2m_get_altp2m(struct vcpu *v) -{ - unsigned int index =3D vcpu_altp2m(v).p2midx; - - if ( index =3D=3D INVALID_ALTP2M ) - return NULL; - - BUG_ON(index >=3D v->domain->nr_altp2m); - - return v->domain->altp2m_p2m[index]; -} - -/* set current alternate p2m table */ -static inline bool altp2m_set_altp2m(struct vcpu *v, unsigned int idx) -{ - struct p2m_domain *orig; - - BUG_ON(idx >=3D v->domain->nr_altp2m); - - if ( idx =3D=3D vcpu_altp2m(v).p2midx ) - return false; - - orig =3D altp2m_get_altp2m(v); - BUG_ON(!orig); - atomic_dec(&orig->active_vcpus); - - vcpu_altp2m(v).p2midx =3D idx; - atomic_inc(&v->domain->altp2m_p2m[idx]->active_vcpus); - - return true; -} - /* Switch alternate p2m for a single vcpu */ bool altp2m_switch_vcpu_by_id(struct vcpu *v, unsigned int idx); =20 @@ -178,8 +145,6 @@ static inline int _altp2m_get_effective_entry(struct p2= m_domain *ap2m, _altp2m_get_effective_entry(ap2m, gfn, mfn, t, a) =20 /* Only declaration is needed. DCE will optimise it out when linking. */ -struct p2m_domain *altp2m_get_altp2m(struct vcpu *v); -bool altp2m_set_altp2m(struct vcpu *v, unsigned int idx); uint16_t altp2m_vcpu_idx(const struct vcpu *v); void altp2m_vcpu_initialise(struct vcpu *v); void altp2m_vcpu_destroy(struct vcpu *v); diff --git a/xen/arch/x86/include/asm/domain.h b/xen/arch/x86/include/asm/d= omain.h index f8038087e612..72460e38f581 100644 --- a/xen/arch/x86/include/asm/domain.h +++ b/xen/arch/x86/include/asm/domain.h @@ -277,8 +277,6 @@ struct paging_vcpu { #define MAX_NR_ALTP2M MAX_EPTP #define MAX_NESTEDP2M 10 =20 -#define INVALID_ALTP2M 0xffff - struct p2m_domain; struct time_scale { int shift; diff --git a/xen/common/altp2m.c b/xen/common/altp2m.c index 989d8bdcb923..a731ad7cdab8 100644 --- a/xen/common/altp2m.c +++ b/xen/common/altp2m.c @@ -5,7 +5,6 @@ #include =20 #include -#include =20 #include =20 diff --git a/xen/include/xen/altp2m.h b/xen/include/xen/altp2m.h index 238c7a935586..58e74be6deb0 100644 --- a/xen/include/xen/altp2m.h +++ b/xen/include/xen/altp2m.h @@ -8,6 +8,10 @@ =20 #include =20 +#include + +#define INVALID_ALTP2M 0xffff + /* * Common alternate p2m declarations that need to be visible * regardless of CONFIG_ALTP2M @@ -27,6 +31,41 @@ static inline bool altp2m_active(const struct domain *d) return d->altp2m_active; } =20 +#ifdef CONFIG_X86 +/* get current alternate p2m table */ +static inline struct p2m_domain *altp2m_get_altp2m(struct vcpu *v) +{ + unsigned int index =3D vcpu_altp2m(v).p2midx; + + if ( index =3D=3D INVALID_ALTP2M ) + return NULL; + + BUG_ON(index >=3D v->domain->nr_altp2m); + + return v->domain->altp2m_p2m[index]; +} + +/* set current alternate p2m table */ +static inline bool altp2m_set_altp2m(struct vcpu *v, unsigned int idx) +{ + struct p2m_domain *orig; + + BUG_ON(idx >=3D v->domain->nr_altp2m); + + if ( idx =3D=3D vcpu_altp2m(v).p2midx ) + return false; + + orig =3D altp2m_get_altp2m(v); + BUG_ON(!orig); + atomic_dec(&orig->active_vcpus); + + vcpu_altp2m(v).p2midx =3D idx; + atomic_inc(&v->domain->altp2m_p2m[idx]->active_vcpus); + + return true; +} +#endif + int do_altp2m_op(XEN_GUEST_HANDLE_PARAM(void) arg); =20 #else /* CONFIG_ALTP2M */ @@ -41,6 +80,10 @@ static inline int do_altp2m_op(XEN_GUEST_HANDLE_PARAM(vo= id) arg) return -EOPNOTSUPP; } =20 +/* Only declaration is needed. DCE will optimise it out when linking. */ +struct p2m_domain *altp2m_get_altp2m(struct vcpu *v); +bool altp2m_set_altp2m(struct vcpu *v, unsigned int idx); + #endif /* CONFIG_ALTP2M */ =20 #endif /* __XEN_ALTP2M_H__ */ --=20 2.34.1