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 15E6FF5A8BC for ; Mon, 20 Apr 2026 20:25:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1286482.1567595 (Exim 4.92) (envelope-from ) id 1wEvBM-0003TB-JP; Mon, 20 Apr 2026 20:25:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1286482.1567595; Mon, 20 Apr 2026 20:25: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 1wEvBM-0003OF-7l; Mon, 20 Apr 2026 20:25:24 +0000 Received: by outflank-mailman (input) for mailman id 1286482; Mon, 20 Apr 2026 19:50:58 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wEue2-0006It-4i for xen-devel@lists.xenproject.org; Mon, 20 Apr 2026 19:50:58 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wEue1-00EWC2-Hl for xen-devel@lists.xenproject.org; Mon, 20 Apr 2026 21:50:57 +0200 Received: from [10.42.69.8] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69e6835b-5cb7-0a2a0a5109dd-0a2a4508c320-32 for ; Mon, 20 Apr 2026 21:50:57 +0200 Received: from [34.202.193.197] (helo=sendmail.purelymail.com) by tlsNG-c1860d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 69e683a0-63b5-0a2a45080019-22cac1c5ec94-3 for ; Mon, 20 Apr 2026 21:50:57 +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:53 +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=PJC6vAx39QYhhYufZEnwEGLPQM6gOCrIWNOV40YBgzgMKXw1ddLQv7aEQcW4Br8sfz1QckVvYSqBT3BbimUkqExezwv7bX14ArzGrsqSzX+CoJpzXkPgUaRHWKLw2YGj+lC/mZtYBkRwezUkaBlyCrSVdoIO5pkVDSvkRFDAEcCQwfWdePjGKfbx907cDTrT6zzhc3KClP6QIwudqs5rLF5+kdfrR+UDmwV7s1AwBdUVAm0sP3CRoOdyh9w9Tcik5i2pmr41aPooN7/HL1uDJ52ABCrMCY4IDtyBMDULt/Vd+1QxNTvCRmGjLOqr/LoKmRKzjEEBlbJvvgDUEQn8bA==; s=purelymail1; d=purelymail.com; v=1; bh=BL+nVHDN3Ay2hLoHiDXEh2wB+DvkjUQnXBWbZIQGO7E=; 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 14/43] altp2m: Move altp2m_{init,teardown} to common code Date: Mon, 20 Apr 2026 15:50:13 -0400 Message-Id: <20260420195042.207624-15-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-c1860d/1776714657-C3D7BDB1-695BFE6A/0/0 X-purgate-type: clean X-purgate-size: 6140 From: Rose Spangler This commit moves the init and teardown routines into common code. The functions are gated by CONFIG_X86, so there is effectively no difference despite common code normally being compiled for ARM. This commit contains only renames/code movement, and no functional change i= s intended. This is commit 3/12 of the altp2m_init/altp2m_teardown routines phase. Signed-off-by: Rose Spangler --- v6: Introduced this patch. --- xen/arch/x86/include/asm/altp2m.h | 8 ----- xen/arch/x86/mm/altp2m.c | 45 ---------------------------- xen/arch/x86/mm/p2m-basic.c | 1 + xen/common/altp2m.c | 49 +++++++++++++++++++++++++++++++ xen/include/xen/altp2m.h | 13 ++++++++ 5 files changed, 63 insertions(+), 53 deletions(-) diff --git a/xen/arch/x86/include/asm/altp2m.h b/xen/arch/x86/include/asm/a= ltp2m.h index 7cff40beb7c6..13017525a62f 100644 --- a/xen/arch/x86/include/asm/altp2m.h +++ b/xen/arch/x86/include/asm/altp2m.h @@ -97,12 +97,6 @@ static inline bool altp2m_set_altp2m(struct vcpu *v, uns= igned int idx) return true; } =20 -/* Initialize altp2m views */ -int altp2m_init(struct domain *d); - -/* Free altp2m views */ -void altp2m_teardown(struct domain *d); - /* Switch alternate p2m for a single vcpu */ bool altp2m_switch_vcpu_by_id(struct vcpu *v, unsigned int idx); =20 @@ -184,8 +178,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. */ -int altp2m_init(struct domain *d); -void altp2m_teardown(struct domain *d); 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); diff --git a/xen/arch/x86/mm/altp2m.c b/xen/arch/x86/mm/altp2m.c index 371bf3f0b8d4..46374373848d 100644 --- a/xen/arch/x86/mm/altp2m.c +++ b/xen/arch/x86/mm/altp2m.c @@ -123,51 +123,6 @@ void altp2m_vcpu_disable_ve(struct vcpu *v) } } =20 -int altp2m_init(struct domain *d) -{ - unsigned int i; - struct p2m_domain *p2m; - struct p2m_domain *hostp2m =3D p2m_get_hostp2m(d); - - altp2m_lock_init(d); - d->altp2m_p2m =3D xvzalloc_array(struct p2m_domain *, d->nr_altp2m); - - if ( !d->altp2m_p2m ) - return -ENOMEM; - - for ( i =3D 0; i < d->nr_altp2m; i++ ) - { - d->altp2m_p2m[i] =3D p2m =3D p2m_init_one(d); - if ( p2m =3D=3D NULL ) - { - altp2m_teardown(d); - return -ENOMEM; - } - p2m->p2m_class =3D p2m_alternate; - p2m->access_required =3D hostp2m->access_required; - _atomic_set(&p2m->active_vcpus, 0); - } - - return 0; -} - -void altp2m_teardown(struct domain *d) -{ - unsigned int i; - struct p2m_domain *p2m; - - for ( i =3D 0; i < d->nr_altp2m; i++ ) - { - if ( !d->altp2m_p2m[i] ) - continue; - p2m =3D d->altp2m_p2m[i]; - d->altp2m_p2m[i] =3D NULL; - p2m_free_one(p2m); - } - - XVFREE(d->altp2m_p2m); -} - 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) diff --git a/xen/arch/x86/mm/p2m-basic.c b/xen/arch/x86/mm/p2m-basic.c index 433e7d08b78f..67cef5d2b6ef 100644 --- a/xen/arch/x86/mm/p2m-basic.c +++ b/xen/arch/x86/mm/p2m-basic.c @@ -11,6 +11,7 @@ * Parts based on earlier work by Michael A Fetterman, Ian Pratt et al. */ =20 +#include #include #include #include diff --git a/xen/common/altp2m.c b/xen/common/altp2m.c index 3a3283f0860a..cda653b713f0 100644 --- a/xen/common/altp2m.c +++ b/xen/common/altp2m.c @@ -2,8 +2,10 @@ #include #include #include +#include =20 #include +#include =20 #include =20 @@ -13,6 +15,53 @@ #include #endif =20 +#if CONFIG_X86 +int altp2m_init(struct domain *d) +{ + unsigned int i; + struct p2m_domain *p2m; + struct p2m_domain *hostp2m =3D p2m_get_hostp2m(d); + + altp2m_lock_init(d); + d->altp2m_p2m =3D xvzalloc_array(struct p2m_domain *, d->nr_altp2m); + + if ( !d->altp2m_p2m ) + return -ENOMEM; + + for ( i =3D 0; i < d->nr_altp2m; i++ ) + { + d->altp2m_p2m[i] =3D p2m =3D p2m_init_one(d); + if ( p2m =3D=3D NULL ) + { + altp2m_teardown(d); + return -ENOMEM; + } + p2m->p2m_class =3D p2m_alternate; + p2m->access_required =3D hostp2m->access_required; + _atomic_set(&p2m->active_vcpus, 0); + } + + return 0; +} + +void altp2m_teardown(struct domain *d) +{ + unsigned int i; + struct p2m_domain *p2m; + + for ( i =3D 0; i < d->nr_altp2m; i++ ) + { + if ( !d->altp2m_p2m[i] ) + continue; + p2m =3D d->altp2m_p2m[i]; + d->altp2m_p2m[i] =3D NULL; + p2m_free_one(p2m); + } + + XVFREE(d->altp2m_p2m); +} +#endif /* CONFIG_X86 */ + /* * altp2m operations are envisioned as being used in several different * modes: diff --git a/xen/include/xen/altp2m.h b/xen/include/xen/altp2m.h index be627152668a..85ef22c2b29e 100644 --- a/xen/include/xen/altp2m.h +++ b/xen/include/xen/altp2m.h @@ -8,6 +8,19 @@ =20 #include =20 +/* + * Common alternate p2m declarations that need to be visible + * regardless of CONFIG_ALTP2M + */ + +#ifdef CONFIG_X86 +/* Initialize altp2m views */ +int altp2m_init(struct domain *d); + +/* Free altp2m views */ +void altp2m_teardown(struct domain *d); +#endif + #ifdef CONFIG_ALTP2M =20 /* Alternate p2m HVM on/off per domain */ --=20 2.34.1