From nobody Thu Jan 8 12:42:42 2026 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; 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; 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=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1767612970653533.2182280874882; Mon, 5 Jan 2026 03:36:10 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1195264.1513233 (Exim 4.92) (envelope-from ) id 1vcisK-0004Ku-4R; Mon, 05 Jan 2026 11:35:52 +0000 Received: by outflank-mailman (output) from mailman id 1195264.1513233; Mon, 05 Jan 2026 11:35:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vcisK-0004Kn-1E; Mon, 05 Jan 2026 11:35:52 +0000 Received: by outflank-mailman (input) for mailman id 1195264; Mon, 05 Jan 2026 11:35:50 +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 1vcisI-00047I-CF for xen-devel@lists.xenproject.org; Mon, 05 Jan 2026 11:35:50 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id af20ca6f-ea2a-11f0-b15e-2bf370ae4941; Mon, 05 Jan 2026 12:35:49 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5593D497; Mon, 5 Jan 2026 03:35:42 -0800 (PST) Received: from e134099.cambridge.arm.com (e134099.arm.com [10.1.198.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 12DBD3F5A1; Mon, 5 Jan 2026 03:35:47 -0800 (PST) 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: af20ca6f-ea2a-11f0-b15e-2bf370ae4941 From: Harry Ramsey To: xen-devel@lists.xenproject.org Cc: Luca.Fancellu@arm.com, Luca Fancellu , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Hari Limaye Subject: [PATCH v2 1/6] arm/mpu: Implement copy_from_paddr for MPU systems Date: Mon, 5 Jan 2026 11:34:58 +0000 Message-ID: <20260105113503.2674777-2-harry.ramsey@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260105113503.2674777-1-harry.ramsey@arm.com> References: <20260105113503.2674777-1-harry.ramsey@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1767612973965154101 Content-Type: text/plain; charset="utf-8" From: Luca Fancellu Implement the function copy_from_paddr variant for MPU systems, using the map_pages_to_xen/destroy_xen_mappings to temporarily map the memory range to be copied. Signed-off-by: Luca Fancellu Signed-off-by: Hari Limaye Signed-off-by: Harry Ramsey Reviewed-by: default avatarMichal Orzel --- v2: - add Michal R-by --- xen/arch/arm/mpu/setup.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/mpu/setup.c b/xen/arch/arm/mpu/setup.c index 163573b932..ec264f54f2 100644 --- a/xen/arch/arm/mpu/setup.c +++ b/xen/arch/arm/mpu/setup.c @@ -91,7 +91,19 @@ void * __init early_fdt_map(paddr_t fdt_paddr) */ void __init copy_from_paddr(void *dst, paddr_t paddr, unsigned long len) { - BUG_ON("unimplemented"); + paddr_t start_pg =3D round_pgdown(paddr); + paddr_t end_pg =3D round_pgup(paddr + len); + unsigned long nr_mfns =3D (end_pg - start_pg) >> PAGE_SHIFT; + mfn_t mfn =3D maddr_to_mfn(start_pg); + + if ( map_pages_to_xen(start_pg, mfn, nr_mfns, PAGE_HYPERVISOR_WC) ) + panic("Unable to map range for copy_from_paddr\n"); + + memcpy(dst, maddr_to_virt(paddr), len); + clean_dcache_va_range(dst, len); + + if ( destroy_xen_mappings(start_pg, end_pg) ) + panic("Unable to unmap range for copy_from_paddr\n"); } =20 void __init remove_early_mappings(void) --=20 2.43.0 From nobody Thu Jan 8 12:42:42 2026 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; 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; 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=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1767612977124754.8901268661738; Mon, 5 Jan 2026 03:36:17 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1195265.1513243 (Exim 4.92) (envelope-from ) id 1vcisN-0004aE-AS; Mon, 05 Jan 2026 11:35:55 +0000 Received: by outflank-mailman (output) from mailman id 1195265.1513243; Mon, 05 Jan 2026 11:35:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vcisN-0004Zy-7X; Mon, 05 Jan 2026 11:35:55 +0000 Received: by outflank-mailman (input) for mailman id 1195265; Mon, 05 Jan 2026 11:35:53 +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 1vcisL-0004YP-Gt for xen-devel@lists.xenproject.org; Mon, 05 Jan 2026 11:35:53 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id afe15c3e-ea2a-11f0-9ccf-f158ae23cfc8; Mon, 05 Jan 2026 12:35:51 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9AB03339; Mon, 5 Jan 2026 03:35:43 -0800 (PST) Received: from e134099.cambridge.arm.com (e134099.arm.com [10.1.198.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6F6E13F5A1; Mon, 5 Jan 2026 03:35:49 -0800 (PST) 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: afe15c3e-ea2a-11f0-9ccf-f158ae23cfc8 From: Harry Ramsey To: xen-devel@lists.xenproject.org Cc: Luca.Fancellu@arm.com, Luca Fancellu , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v2 2/6] arm/mpu: Implement vmap functions for MPU Date: Mon, 5 Jan 2026 11:34:59 +0000 Message-ID: <20260105113503.2674777-3-harry.ramsey@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260105113503.2674777-1-harry.ramsey@arm.com> References: <20260105113503.2674777-1-harry.ramsey@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1767612979776154100 Content-Type: text/plain; charset="utf-8" From: Luca Fancellu HAS_VMAP is not enabled on MPU systems, but the vmap functions are used in places across common code. In order to keep the existing code and maintain correct functionality, implement the `vmap_contig` and `vunmap` functions for MPU systems. Introduce a helper function `destroy_xen_mapping_containing` to aid with unmapping an entire region when only the start address is known. Signed-off-by: Luca Fancellu Signed-off-by: Harry Ramsey --- v2: - Rename `destroy_entire_xen_mapping` to `destroy_xen_mapping_containing` - Improve code documentation. - Refactor nested code. - Fix ignored rc error code in `destroy_xen_mapping_containing`. --- xen/arch/arm/include/asm/mpu/mm.h | 10 +++++ xen/arch/arm/mpu/mm.c | 74 ++++++++++++++++++++++++++----- xen/arch/arm/mpu/vmap.c | 14 ++++-- 3 files changed, 83 insertions(+), 15 deletions(-) diff --git a/xen/arch/arm/include/asm/mpu/mm.h b/xen/arch/arm/include/asm/m= pu/mm.h index e1ded6521d..1b5ffa5b64 100644 --- a/xen/arch/arm/include/asm/mpu/mm.h +++ b/xen/arch/arm/include/asm/mpu/mm.h @@ -111,6 +111,16 @@ pr_t pr_of_addr(paddr_t base, paddr_t limit, unsigned = int flags); int mpumap_contains_region(pr_t *table, uint8_t nr_regions, paddr_t base, paddr_t limit, uint8_t *index); =20 + +/* + * Destroys and frees (if reference count is 0) an entire xen mapping on M= PU + * systems where only the start address is known. + * + * @param s Start address of memory region to be destroyed. + * @return: 0 on success, negative on error. + */ +int destroy_xen_mapping_containing(paddr_t s); + #endif /* __ARM_MPU_MM_H__ */ =20 /* diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c index 687dec3bc6..207e8d2d91 100644 --- a/xen/arch/arm/mpu/mm.c +++ b/xen/arch/arm/mpu/mm.c @@ -290,6 +290,42 @@ static void disable_mpu_region_from_index(uint8_t inde= x) write_protection_region(&xen_mpumap[index], index); } =20 +/* + * Free a xen_mpumap entry given the index. A mpu region is actually disab= led + * when the refcount is 0 and the region type is MPUMAP_REGION_FOUND. + * + * @param idx Index of the mpumap entry. + * @param region_found_type MPUMAP_REGION_* value. + * @return 0 on success, otherwise negative on error. + */ +static int xen_mpumap_free_entry(uint8_t idx, int region_found_type) +{ + ASSERT(spin_is_locked(&xen_mpumap_lock)); + ASSERT(idx !=3D INVALID_REGION_IDX); + + if ( MPUMAP_REGION_OVERLAP =3D=3D region_found_type ) + { + printk(XENLOG_ERR "Cannot remove an overlapping region\n"); + return -EINVAL; + } + + if ( xen_mpumap[idx].refcount ) + { + xen_mpumap[idx].refcount -=3D 1; + return 0; + } + + if ( MPUMAP_REGION_FOUND =3D=3D region_found_type ) + disable_mpu_region_from_index(idx); + else + { + printk(XENLOG_ERR "Cannot remove a partial region\n"); + return -EINVAL; + } + + return 0; +} + /* * Update the entry in the MPU memory region mapping table (xen_mpumap) fo= r the * given memory range and flags, creating one if none exists. @@ -357,18 +393,7 @@ static int xen_mpumap_update_entry(paddr_t base, paddr= _t limit, return -EINVAL; } =20 - if ( xen_mpumap[idx].refcount =3D=3D 0 ) - { - if ( MPUMAP_REGION_FOUND =3D=3D rc ) - disable_mpu_region_from_index(idx); - else - { - printk("Cannot remove a partial region\n"); - return -EINVAL; - } - } - else - xen_mpumap[idx].refcount -=3D 1; + return xen_mpumap_free_entry(idx, rc); } =20 return 0; @@ -418,6 +443,31 @@ int destroy_xen_mappings(unsigned long s, unsigned lon= g e) return xen_mpumap_update(s, e, 0); } =20 +int destroy_xen_mapping_containing(paddr_t s) +{ + int rc; + uint8_t idx; + + ASSERT(IS_ALIGNED(s, PAGE_SIZE)); + + spin_lock(&xen_mpumap_lock); + + rc =3D mpumap_contains_region(xen_mpumap, max_mpu_regions, s, s + PAGE= _SIZE, + &idx); + if ( rc =3D=3D MPUMAP_REGION_NOTFOUND ) + { + printk(XENLOG_ERR "Cannot remove entry that does not exist"); + return -EINVAL; + } + + /* As we are unmapping entire region use MPUMAP_REGION_FOUND instead */ + rc =3D xen_mpumap_free_entry(idx, MPUMAP_REGION_FOUND); + + spin_unlock(&xen_mpumap_lock); + + return rc; +} + int map_pages_to_xen(unsigned long virt, mfn_t mfn, unsigned long nr_mfns, unsigned int flags) { diff --git a/xen/arch/arm/mpu/vmap.c b/xen/arch/arm/mpu/vmap.c index f977b79cd4..54d949e7ce 100644 --- a/xen/arch/arm/mpu/vmap.c +++ b/xen/arch/arm/mpu/vmap.c @@ -1,19 +1,27 @@ /* SPDX-License-Identifier: GPL-2.0-only */ =20 #include +#include #include #include #include =20 void *vmap_contig(mfn_t mfn, unsigned int nr) { - BUG_ON("unimplemented"); - return NULL; + paddr_t base =3D mfn_to_maddr(mfn); + + if ( map_pages_to_xen(base, mfn, nr, PAGE_HYPERVISOR ) ) + return NULL; + + return maddr_to_virt(base); } =20 void vunmap(const void *va) { - BUG_ON("unimplemented"); + paddr_t base =3D virt_to_maddr(va); + + if ( destroy_xen_mapping_containing(base) ) + panic("Failed to vunmap region\n"); } =20 /* --=20 2.43.0 From nobody Thu Jan 8 12:42:42 2026 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; 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; 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=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1767612973459135.30979283327247; Mon, 5 Jan 2026 03:36:13 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1195266.1513249 (Exim 4.92) (envelope-from ) id 1vcisN-0004cj-KU; Mon, 05 Jan 2026 11:35:55 +0000 Received: by outflank-mailman (output) from mailman id 1195266.1513249; Mon, 05 Jan 2026 11:35:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vcisN-0004bm-Dn; Mon, 05 Jan 2026 11:35:55 +0000 Received: by outflank-mailman (input) for mailman id 1195266; Mon, 05 Jan 2026 11:35:53 +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 1vcisL-00047I-Oq for xen-devel@lists.xenproject.org; Mon, 05 Jan 2026 11:35:53 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id b0f8bc5c-ea2a-11f0-b15e-2bf370ae4941; Mon, 05 Jan 2026 12:35:53 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4DCEB497; Mon, 5 Jan 2026 03:35:45 -0800 (PST) Received: from e134099.cambridge.arm.com (e134099.arm.com [10.1.198.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B24C83F5A1; Mon, 5 Jan 2026 03:35:50 -0800 (PST) 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: b0f8bc5c-ea2a-11f0-b15e-2bf370ae4941 From: Harry Ramsey To: xen-devel@lists.xenproject.org Cc: Luca.Fancellu@arm.com, Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Penny Zheng , Wei Chen , Luca Fancellu , Hari Limaye Subject: [PATCH v2 3/6] arm/mpu: Implement free_init_memory for MPU systems Date: Mon, 5 Jan 2026 11:35:00 +0000 Message-ID: <20260105113503.2674777-4-harry.ramsey@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260105113503.2674777-1-harry.ramsey@arm.com> References: <20260105113503.2674777-1-harry.ramsey@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1767612975548154100 Content-Type: text/plain; charset="utf-8" From: Penny Zheng Implement the function `free_init_memory` for MPU systems. In order to support this, the function `modify_xen_mappings` is implemented. On MPU systems, we map the init text and init data sections using separate MPU memory regions. Therefore these are removed separately in `free_init_memory`. Additionally remove warning messages from `is_mm_attr_match` as some permissions can now be updated by `xen_mpumap_update_entry`. Signed-off-by: Penny Zheng Signed-off-by: Wei Chen Signed-off-by: Luca Fancellu Signed-off-by: Hari Limaye Signed-off-by: Harry Ramsey --- v2: - Refactor `is_mm_attr_match` to return logical values regarding the permission mismatch. - Improve code documentation. --- xen/arch/arm/include/asm/mpu/mm.h | 6 +- xen/arch/arm/include/asm/setup.h | 2 + xen/arch/arm/mpu/mm.c | 113 +++++++++++++++++++++++------- 3 files changed, 95 insertions(+), 26 deletions(-) diff --git a/xen/arch/arm/include/asm/mpu/mm.h b/xen/arch/arm/include/asm/m= pu/mm.h index 1b5ffa5b64..f0941de295 100644 --- a/xen/arch/arm/include/asm/mpu/mm.h +++ b/xen/arch/arm/include/asm/mpu/mm.h @@ -15,7 +15,11 @@ #define MPUMAP_REGION_FOUND 1 #define MPUMAP_REGION_INCLUSIVE 2 =20 -#define INVALID_REGION_IDX 0xFFU +#define MPU_ATTR_RO_MISMATCH -1 +#define MPU_ATTR_XN_MISMATCH -2 +#define MPU_ATTR_AI_MISMATCH -3 + +#define INVALID_REGION_IDX 0xFFU =20 extern struct page_info *frame_table; =20 diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/se= tup.h index 1eaf13bd66..005cf7be59 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -65,6 +65,8 @@ int map_irq_to_domain(struct domain *d, unsigned int irq, int map_range_to_domain(const struct dt_device_node *dev, uint64_t addr, uint64_t len, void *data); =20 +extern const char __init_data_begin[], __bss_start[], __bss_end[]; + struct init_info { /* Pointer to the stack, used by head.S when entering in C */ diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c index 207e8d2d91..4194d4fefd 100644 --- a/xen/arch/arm/mpu/mm.c +++ b/xen/arch/arm/mpu/mm.c @@ -171,33 +171,18 @@ int mpumap_contains_region(pr_t *table, uint8_t nr_re= gions, paddr_t base, return MPUMAP_REGION_NOTFOUND; } =20 -static bool is_mm_attr_match(pr_t *region, unsigned int attributes) +static int is_mm_attr_match(pr_t *region, unsigned int attributes) { if ( region->prbar.reg.ro !=3D PAGE_RO_MASK(attributes) ) - { - printk(XENLOG_WARNING - "Mismatched Access Permission attributes (%#x instead of %#= x)\n", - region->prbar.reg.ro, PAGE_RO_MASK(attributes)); - return false; - } + return MPU_ATTR_RO_MISMATCH; =20 if ( region->prbar.reg.xn !=3D PAGE_XN_MASK(attributes) ) - { - printk(XENLOG_WARNING - "Mismatched Execute Never attributes (%#x instead of %#x)\n= ", - region->prbar.reg.xn, PAGE_XN_MASK(attributes)); - return false; - } + return MPU_ATTR_XN_MISMATCH; =20 if ( region->prlar.reg.ai !=3D PAGE_AI_MASK(attributes) ) - { - printk(XENLOG_WARNING - "Mismatched Memory Attribute Index (%#x instead of %#x)\n", - region->prlar.reg.ai, PAGE_AI_MASK(attributes)); - return false; - } + return MPU_ATTR_AI_MISMATCH; =20 - return true; + return 0; } =20 /* Map a frame table to cover physical addresses ps through pe */ @@ -357,12 +342,45 @@ static int xen_mpumap_update_entry(paddr_t base, padd= r_t limit, */ if ( flags_has_page_present && (rc >=3D MPUMAP_REGION_FOUND) ) { - if ( !is_mm_attr_match(&xen_mpumap[idx], flags) ) + int attr_match =3D is_mm_attr_match(&xen_mpumap[idx], flags); + + /* We do not support modifying AI attribute. */ + if ( MPU_ATTR_AI_MISMATCH =3D=3D attr_match ) { - printk("Modifying an existing entry is not supported\n"); + printk(XENLOG_ERR + "Modifying memory attribute is not supported\n"); return -EINVAL; } =20 + /* + * Permissions RO and XN can be changed only by the full region. + * Permissions that match can continue and just increment refcount. + */ + if ( MPU_ATTR_RO_MISMATCH =3D=3D attr_match || + MPU_ATTR_XN_MISMATCH =3D=3D attr_match ) + { + if ( rc =3D=3D MPUMAP_REGION_INCLUSIVE ) + { + printk(XENLOG_ERR + "Cannot modify partial region permissions\n"); + return -EINVAL; + } + + if ( xen_mpumap[idx].refcount !=3D 0 ) + { + printk(XENLOG_ERR + "Cannot modify memory permissions for a region mapp= ed multiple times\n"); + return -EINVAL; + } + + /* Set new permission */ + xen_mpumap[idx].prbar.reg.ro =3D PAGE_RO_MASK(flags); + xen_mpumap[idx].prbar.reg.xn =3D PAGE_XN_MASK(flags); + + write_protection_region(&xen_mpumap[idx], idx); + return 0; + } + /* Check for overflow of refcount before incrementing. */ if ( xen_mpumap[idx].refcount =3D=3D 0xFF ) { @@ -506,8 +524,7 @@ void __init setup_mm_helper(void) =20 int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) { - BUG_ON("unimplemented"); - return -EINVAL; + return xen_mpumap_update(s, e, nf); } =20 void dump_hyp_walk(vaddr_t addr) @@ -518,7 +535,53 @@ void dump_hyp_walk(vaddr_t addr) /* Release all __init and __initdata ranges to be reused */ void free_init_memory(void) { - BUG_ON("unimplemented"); + unsigned long inittext_end =3D (unsigned long)__init_data_begin; + unsigned long len =3D __init_end - __init_begin; + uint8_t idx; + int rc; + + /* Modify inittext region to be read/write instead of read/execute. */ + rc =3D modify_xen_mappings((unsigned long)__init_begin, inittext_end, + PAGE_HYPERVISOR_RW); + if ( rc ) + panic("Unable to map RW the init text section (rc =3D %d)\n", rc); + + /* + * From now on, init will not be used for execution anymore, + * so nuke the instruction cache to remove entries related to init. + */ + invalidate_icache_local(); + + /* + * The initdata region already has read/write permissions so it can ju= st be + * zeroed out. + */ + memset(__init_begin, 0, len); + + rc =3D destroy_xen_mappings((unsigned long)__init_begin, inittext_end); + if ( rc ) + panic("Unable to remove init text section (rc =3D %d)\n", rc); + + /* + * The initdata and bss sections are mapped using a single MPU region,= so + * modify the start of this region to remove the initdata section. + */ + spin_lock(&xen_mpumap_lock); + + rc =3D mpumap_contains_region(xen_mpumap, max_mpu_regions, + (unsigned long)__init_data_begin, + (unsigned long)__bss_end, + &idx); + if ( rc < MPUMAP_REGION_FOUND ) + panic("Unable to find bss data section (rc =3D %d)\n", rc); + + /* bss data section is shrunk and now starts from __bss_start */ + pr_set_base(&xen_mpumap[idx], (unsigned long)__bss_start); + + write_protection_region(&xen_mpumap[idx], idx); + context_sync_mpu(); + + spin_unlock(&xen_mpumap_lock); } =20 void __iomem *ioremap_attr(paddr_t start, size_t len, unsigned int flags) --=20 2.43.0 From nobody Thu Jan 8 12:42:42 2026 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; 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; 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=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1767612974846320.05220835757245; Mon, 5 Jan 2026 03:36:14 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1195267.1513254 (Exim 4.92) (envelope-from ) id 1vcisN-0004jy-Uv; Mon, 05 Jan 2026 11:35:55 +0000 Received: by outflank-mailman (output) from mailman id 1195267.1513254; Mon, 05 Jan 2026 11:35:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vcisN-0004hj-PI; Mon, 05 Jan 2026 11:35:55 +0000 Received: by outflank-mailman (input) for mailman id 1195267; Mon, 05 Jan 2026 11:35:55 +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 1vcisN-00047I-2K for xen-devel@lists.xenproject.org; Mon, 05 Jan 2026 11:35:55 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id b1c18be3-ea2a-11f0-b15e-2bf370ae4941; Mon, 05 Jan 2026 12:35:54 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AEF01339; Mon, 5 Jan 2026 03:35:46 -0800 (PST) Received: from e134099.cambridge.arm.com (e134099.arm.com [10.1.198.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 68AD63F5A1; Mon, 5 Jan 2026 03:35:52 -0800 (PST) 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: b1c18be3-ea2a-11f0-b15e-2bf370ae4941 From: Harry Ramsey To: xen-devel@lists.xenproject.org Cc: Luca.Fancellu@arm.com, Luca Fancellu , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Hari Limaye Subject: [PATCH v2 4/6] arm/mpu: Introduce modify_after_init_mappings Date: Mon, 5 Jan 2026 11:35:01 +0000 Message-ID: <20260105113503.2674777-5-harry.ramsey@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260105113503.2674777-1-harry.ramsey@arm.com> References: <20260105113503.2674777-1-harry.ramsey@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1767612988430154100 Content-Type: text/plain; charset="utf-8" From: Luca Fancellu During `init_done`, Xen sets the permissions of all symbols marked with __ro_after_init to be read-only. This does not work on MPU systems at present because part-region modification is not supported. Therefore introduce the function `modify_after_init_mappings` for MMU and MPU, to handle the divergent approaches to setting permissions of __ro_after_init symbols. For MPU systems `modify_xen_mappings` will shrink the RW mapping on one side and extend the RO mapping on the other. This approach prevents wasting an additional region between RW and RO mappings. As the new function is marked with __init, it needs to be called before `free_init_memory`. Signed-off-by: Luca Fancellu Signed-off-by: Hari Limaye Signed-off-by: Harry Ramsey --- v2: - No changes --- xen/arch/arm/include/asm/setup.h | 3 +++ xen/arch/arm/mmu/setup.c | 15 ++++++++++++ xen/arch/arm/mpu/mm.c | 2 +- xen/arch/arm/mpu/setup.c | 40 ++++++++++++++++++++++++++++++++ xen/arch/arm/setup.c | 15 ++---------- 5 files changed, 61 insertions(+), 14 deletions(-) diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/se= tup.h index 005cf7be59..899e33925c 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -78,6 +78,9 @@ struct init_info paddr_t consider_modules(paddr_t s, paddr_t e, uint32_t size, paddr_t alig= n, int first_mod); =20 +/* Modify some mappings after the init is done */ +void modify_after_init_mappings(void); + #endif /* * Local variables: diff --git a/xen/arch/arm/mmu/setup.c b/xen/arch/arm/mmu/setup.c index 9b874f8ab2..d042f73597 100644 --- a/xen/arch/arm/mmu/setup.c +++ b/xen/arch/arm/mmu/setup.c @@ -213,6 +213,21 @@ void __init remove_early_mappings(void) BUG_ON(rc); } =20 +void __init modify_after_init_mappings(void) +{ + /* + * We have finished booting. Mark the section .data.ro_after_init + * read-only. + */ + int rc =3D modify_xen_mappings((unsigned long)&__ro_after_init_start, + (unsigned long)&__ro_after_init_end, + PAGE_HYPERVISOR_RO); + + if ( rc ) + panic("Unable to mark the .data.ro_after_init section read-only (r= c =3D %d)\n", + rc); +} + /* * After boot, Xen page-tables should not contain mapping that are both * Writable and eXecutables. diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c index 4194d4fefd..7fc1658bb2 100644 --- a/xen/arch/arm/mpu/mm.c +++ b/xen/arch/arm/mpu/mm.c @@ -32,7 +32,7 @@ DECLARE_BITMAP(xen_mpumap_mask, MAX_MPU_REGION_NR) \ /* EL2 Xen MPU memory region mapping table. */ pr_t __cacheline_aligned __section(".data") xen_mpumap[MAX_MPU_REGION_NR]; =20 -static DEFINE_SPINLOCK(xen_mpumap_lock); +DEFINE_SPINLOCK(xen_mpumap_lock); =20 static void __init __maybe_unused build_assertions(void) { diff --git a/xen/arch/arm/mpu/setup.c b/xen/arch/arm/mpu/setup.c index ec264f54f2..55317ee318 100644 --- a/xen/arch/arm/mpu/setup.c +++ b/xen/arch/arm/mpu/setup.c @@ -8,11 +8,14 @@ #include #include #include +#include #include =20 static paddr_t __initdata mapped_fdt_base =3D INVALID_PADDR; static paddr_t __initdata mapped_fdt_limit =3D INVALID_PADDR; =20 +extern spinlock_t xen_mpumap_lock; + void __init setup_pagetables(void) {} =20 void * __init early_fdt_map(paddr_t fdt_paddr) @@ -106,6 +109,43 @@ void __init copy_from_paddr(void *dst, paddr_t paddr, = unsigned long len) panic("Unable to unmap range for copy_from_paddr\n"); } =20 +void __init modify_after_init_mappings(void) +{ + int rc; + uint8_t idx_rodata; + uint8_t idx_rwdata; + + spin_lock(&xen_mpumap_lock); + + rc =3D mpumap_contains_region(xen_mpumap, max_mpu_regions, + (unsigned long)_srodata, + (unsigned long)_erodata, + &idx_rodata); + + if ( rc < MPUMAP_REGION_FOUND ) + panic("Unable to find rodata section (rc =3D %d)\n", rc); + + rc =3D mpumap_contains_region(xen_mpumap, max_mpu_regions, + (unsigned long)__ro_after_init_start, + (unsigned long)__init_begin, + &idx_rwdata); + + if ( rc < MPUMAP_REGION_FOUND ) + panic("Unable to find rwdata section (rc =3D %d)\n", rc); + + /* Shrink rwdata section to begin at __ro_after_init_end */ + pr_set_base(&xen_mpumap[idx_rwdata], (unsigned long)__ro_after_init_en= d); + + /* Extend rodata section to end at __ro_after_init_end */ + pr_set_limit(&xen_mpumap[idx_rodata], (unsigned long)__ro_after_init_e= nd); + + write_protection_region(&xen_mpumap[idx_rwdata], idx_rwdata); + write_protection_region(&xen_mpumap[idx_rodata], idx_rodata); + context_sync_mpu(); + + spin_unlock(&xen_mpumap_lock); +} + void __init remove_early_mappings(void) { int rc =3D destroy_xen_mappings(round_pgdown(mapped_fdt_base), diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 7ad870e382..6310a47d68 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -66,23 +66,12 @@ domid_t __read_mostly max_init_domid; =20 static __used void noreturn init_done(void) { - int rc; - /* Must be done past setting system_state. */ unregister_init_virtual_region(); =20 - free_init_memory(); + modify_after_init_mappings(); =20 - /* - * We have finished booting. Mark the section .data.ro_after_init - * read-only. - */ - rc =3D modify_xen_mappings((unsigned long)&__ro_after_init_start, - (unsigned long)&__ro_after_init_end, - PAGE_HYPERVISOR_RO); - if ( rc ) - panic("Unable to mark the .data.ro_after_init section read-only (r= c =3D %d)\n", - rc); + free_init_memory(); =20 startup_cpu_idle_loop(); } --=20 2.43.0 From nobody Thu Jan 8 12:42:42 2026 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; 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; 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=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1767612981500476.0425119410255; Mon, 5 Jan 2026 03:36:21 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1195268.1513273 (Exim 4.92) (envelope-from ) id 1vcisP-0005Fw-F5; Mon, 05 Jan 2026 11:35:57 +0000 Received: by outflank-mailman (output) from mailman id 1195268.1513273; Mon, 05 Jan 2026 11:35:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vcisP-0005F9-8B; Mon, 05 Jan 2026 11:35:57 +0000 Received: by outflank-mailman (input) for mailman id 1195268; Mon, 05 Jan 2026 11:35:56 +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 1vcisO-00047I-Bb for xen-devel@lists.xenproject.org; Mon, 05 Jan 2026 11:35:56 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id b2a8ba1d-ea2a-11f0-b15e-2bf370ae4941; Mon, 05 Jan 2026 12:35:55 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 488CC497; Mon, 5 Jan 2026 03:35:48 -0800 (PST) Received: from e134099.cambridge.arm.com (e134099.arm.com [10.1.198.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C65AF3F5A1; Mon, 5 Jan 2026 03:35:53 -0800 (PST) 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: b2a8ba1d-ea2a-11f0-b15e-2bf370ae4941 From: Harry Ramsey To: xen-devel@lists.xenproject.org Cc: Luca.Fancellu@arm.com, Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Penny Zheng , Wei Chen , Luca Fancellu Subject: [PATCH v2 5/6] arm: Use secure hypervisor timer in MPU system Date: Mon, 5 Jan 2026 11:35:02 +0000 Message-ID: <20260105113503.2674777-6-harry.ramsey@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260105113503.2674777-1-harry.ramsey@arm.com> References: <20260105113503.2674777-1-harry.ramsey@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1767612983567154100 Content-Type: text/plain; charset="utf-8" From: Penny Zheng As MPU systems only have one secure state, we have to use secure EL2 hypervisor timer for Xen in secure EL2. Signed-off-by: Penny Zheng Signed-off-by: Wei Chen Signed-off-by: Luca Fancellu Signed-off-by: Harry Ramsey --- v2: - Remove unncessary kconfig attribute. - Remove unncessary hypervisor timer macro. --- xen/arch/arm/include/asm/arm64/sysregs.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/xen/arch/arm/include/asm/arm64/sysregs.h b/xen/arch/arm/includ= e/asm/arm64/sysregs.h index 7dfd20414d..19d409d3eb 100644 --- a/xen/arch/arm/include/asm/arm64/sysregs.h +++ b/xen/arch/arm/include/asm/arm64/sysregs.h @@ -462,6 +462,17 @@ #define ZCR_ELx_LEN_SIZE 9 #define ZCR_ELx_LEN_MASK 0x1ff =20 +#ifdef CONFIG_MPU +/* + * The Armv8-R AArch64 architecture always executes code in Secure + * state with EL2 as the highest exception level. + * + * Hypervisor timer registers for Secure EL2. + */ +#define CNTHP_CTL_EL2 CNTHPS_CTL_EL2 +#define CNTHP_CVAL_EL2 CNTHPS_CVAL_EL2 +#endif + #define REGION_TEXT_PRBAR 0x38 /* SH=3D11 AP=3D10 XN=3D00 */ #define REGION_RO_PRBAR 0x3A /* SH=3D11 AP=3D10 XN=3D10 */ #define REGION_DATA_PRBAR 0x32 /* SH=3D11 AP=3D00 XN=3D10 */ --=20 2.43.0 From nobody Thu Jan 8 12:42:42 2026 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; 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; 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=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1767612983129793.1074594185155; Mon, 5 Jan 2026 03:36:23 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1195269.1513283 (Exim 4.92) (envelope-from ) id 1vcisS-0005dB-NZ; Mon, 05 Jan 2026 11:36:00 +0000 Received: by outflank-mailman (output) from mailman id 1195269.1513283; Mon, 05 Jan 2026 11:36:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vcisS-0005d1-Jq; Mon, 05 Jan 2026 11:36:00 +0000 Received: by outflank-mailman (input) for mailman id 1195269; Mon, 05 Jan 2026 11:35:58 +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 1vcisQ-0004YP-Ty for xen-devel@lists.xenproject.org; Mon, 05 Jan 2026 11:35:58 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id b3955a49-ea2a-11f0-9ccf-f158ae23cfc8; Mon, 05 Jan 2026 12:35:57 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DC96B339; Mon, 5 Jan 2026 03:35:49 -0800 (PST) Received: from e134099.cambridge.arm.com (e134099.arm.com [10.1.198.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 633843F5A1; Mon, 5 Jan 2026 03:35:55 -0800 (PST) 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: b3955a49-ea2a-11f0-9ccf-f158ae23cfc8 From: Harry Ramsey To: xen-devel@lists.xenproject.org Cc: Luca.Fancellu@arm.com, Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Penny Zheng , Wei Chen , Luca Fancellu Subject: [PATCH v2 6/6] arm/mpu: Map domain page in AArch64 MPU systems Date: Mon, 5 Jan 2026 11:35:03 +0000 Message-ID: <20260105113503.2674777-7-harry.ramsey@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260105113503.2674777-1-harry.ramsey@arm.com> References: <20260105113503.2674777-1-harry.ramsey@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1767612985623154100 Content-Type: text/plain; charset="utf-8" From: Penny Zheng In MPU systems, we implement map_domain_page()/unmap_domain_page() through mapping the domain page with a MPU region on demand. Signed-off-by: Penny Zheng Signed-off-by: Wei Chen Signed-off-by: Luca Fancellu Signed-off-by: Harry Ramsey --- v2: - No changes --- xen/arch/arm/Kconfig | 1 + xen/arch/arm/mpu/Makefile | 1 + xen/arch/arm/mpu/domain-page.c | 53 ++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 xen/arch/arm/mpu/domain-page.c diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index cf6af68299..baa6c4cf15 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -91,6 +91,7 @@ config MMU =20 config MPU bool "MPU" if UNSUPPORTED + select ARCH_MAP_DOMAIN_PAGE if ARM_64 select STATIC_MEMORY help Memory Protection Unit (MPU). Select if you plan to run Xen on ARMv8-R diff --git a/xen/arch/arm/mpu/Makefile b/xen/arch/arm/mpu/Makefile index 4963c8b550..940297af3f 100644 --- a/xen/arch/arm/mpu/Makefile +++ b/xen/arch/arm/mpu/Makefile @@ -1,5 +1,6 @@ obj-$(CONFIG_ARM_32) +=3D arm32/ obj-$(CONFIG_ARM_64) +=3D arm64/ +obj-$(CONFIG_ARM_64) +=3D domain-page.o obj-y +=3D mm.o obj-y +=3D p2m.o obj-y +=3D setup.init.o diff --git a/xen/arch/arm/mpu/domain-page.c b/xen/arch/arm/mpu/domain-page.c new file mode 100644 index 0000000000..1b43bf82a6 --- /dev/null +++ b/xen/arch/arm/mpu/domain-page.c @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include +#include +#include +#include + +void *map_domain_page_global(mfn_t mfn) +{ + BUG_ON("unimplemented"); + return NULL; +} + +/* Map a page of domheap memory */ +void *map_domain_page(mfn_t mfn) +{ + paddr_t pa =3D mfn_to_maddr(mfn); + + if ( map_pages_to_xen((unsigned long)pa, mfn, 1, PAGE_HYPERVISOR_RW) ) + return NULL; + + return maddr_to_virt(pa); +} + +/* Release a mapping taken with map_domain_page() */ +void unmap_domain_page(const void *ptr) +{ + paddr_t base =3D virt_to_maddr(ptr); + + if ( destroy_xen_mapping_containing(base) ) + panic("Failed to unmap domain page\n"); +} + +mfn_t domain_page_map_to_mfn(const void *ptr) +{ + BUG_ON("unimplemented"); + return INVALID_MFN; +} + +void unmap_domain_page_global(const void *va) +{ + BUG_ON("unimplemented"); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ --=20 2.43.0