From patchwork Mon Mar 17 20:07:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 14019943 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 48A27C282EC for ; Mon, 17 Mar 2025 20:08:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.918100.1322898 (Exim 4.92) (envelope-from ) id 1tuGkd-0007zk-9c; Mon, 17 Mar 2025 20:07:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 918100.1322898; Mon, 17 Mar 2025 20:07: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 1tuGkd-0007zW-5u; Mon, 17 Mar 2025 20:07:55 +0000 Received: by outflank-mailman (input) for mailman id 918100; Mon, 17 Mar 2025 20:07:54 +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 1tuGkc-00063P-1N for xen-devel@lists.xenproject.org; Mon, 17 Mar 2025 20:07:54 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 798e3c1e-036b-11f0-9899-31a8f345e629; Mon, 17 Mar 2025 21:07:38 +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 B91BE152B; Mon, 17 Mar 2025 13:07:46 -0700 (PDT) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E8E073F7BD; Mon, 17 Mar 2025 13:07:36 -0700 (PDT) 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: 798e3c1e-036b-11f0-9899-31a8f345e629 From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v3 1/7] arm/mpu: Add HYPERVISOR_VIRT_START and avoid a check in xen.lds.S Date: Mon, 17 Mar 2025 20:07:21 +0000 Message-Id: <20250317200727.798696-2-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317200727.798696-1-luca.fancellu@arm.com> References: <20250317200727.798696-1-luca.fancellu@arm.com> MIME-Version: 1.0 The define HYPERVISOR_VIRT_START is required by the common code, even if MPU system doesn't use virtual memory, define it in mpu/layout.h in order to reuse existing code. Disable a check in the linker script for arm for !MMU systems. Signed-off-by: Luca Fancellu Reviewed-by: Michal Orzel --- v3 changes: - no changes v2 changes: - Add Michal R-by --- xen/arch/arm/include/asm/mpu/layout.h | 2 ++ xen/arch/arm/xen.lds.S | 2 ++ 2 files changed, 4 insertions(+) diff --git a/xen/arch/arm/include/asm/mpu/layout.h b/xen/arch/arm/include/asm/mpu/layout.h index d6d397f4c2ac..248e55f8882d 100644 --- a/xen/arch/arm/include/asm/mpu/layout.h +++ b/xen/arch/arm/include/asm/mpu/layout.h @@ -22,6 +22,8 @@ */ #define XEN_VIRT_START _AT(paddr_t, XEN_START_ADDRESS) +#define HYPERVISOR_VIRT_START XEN_VIRT_START + #endif /* __ARM_MPU_LAYOUT_H__ */ /* * Local variables: diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S index bbccff1a0350..4342e54422a7 100644 --- a/xen/arch/arm/xen.lds.S +++ b/xen/arch/arm/xen.lds.S @@ -239,4 +239,6 @@ ASSERT(IS_ALIGNED(__bss_start, POINTER_ALIGN), "__bss_start is misaligned") ASSERT(IS_ALIGNED(__bss_end, POINTER_ALIGN), "__bss_end is misaligned") /* To simplify the logic in head.S, we want to _end to be page aligned */ ASSERT(IS_ALIGNED(_end, PAGE_SIZE), "_end is not page aligned") +#ifdef CONFIG_MMU ASSERT((_end - _start) <= XEN_VIRT_SIZE, "Xen is too big") +#endif From patchwork Mon Mar 17 20:07:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 14019942 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 D248BC35FFF for ; Mon, 17 Mar 2025 20:08:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.918087.1322848 (Exim 4.92) (envelope-from ) id 1tuGkS-0006Tp-Nw; Mon, 17 Mar 2025 20:07:44 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 918087.1322848; Mon, 17 Mar 2025 20:07:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tuGkS-0006Th-Jw; Mon, 17 Mar 2025 20:07:44 +0000 Received: by outflank-mailman (input) for mailman id 918087; Mon, 17 Mar 2025 20:07: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 1tuGkQ-00063P-Nj for xen-devel@lists.xenproject.org; Mon, 17 Mar 2025 20:07:42 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 7a74e201-036b-11f0-9899-31a8f345e629; Mon, 17 Mar 2025 21:07:40 +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 6CCDC1BB0; Mon, 17 Mar 2025 13:07:48 -0700 (PDT) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3E5BB3F63F; Mon, 17 Mar 2025 13:07:38 -0700 (PDT) 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: 7a74e201-036b-11f0-9899-31a8f345e629 From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Penny Zheng , Wei Chen Subject: [PATCH v3 2/7] xen/arm: Implement virt/maddr conversion in MPU system Date: Mon, 17 Mar 2025 20:07:22 +0000 Message-Id: <20250317200727.798696-3-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317200727.798696-1-luca.fancellu@arm.com> References: <20250317200727.798696-1-luca.fancellu@arm.com> MIME-Version: 1.0 From: Penny Zheng virt_to_maddr and maddr_to_virt are used widely in Xen code. So even there is no VMSA in MPU system, we keep the interface in MPU to to avoid changing the existing common code. In order to do that, move the virt_to_maddr() and maddr_to_virt() definitions to mmu/mm.h, move the include of memory management subsystems (MMU/MPU) on a different place because the mentioned helpers needs visibility of some macro in asm/mm.h. Finally implement virt_to_maddr() and maddr_to_virt() for MPU systems under mpu/mm.h, the MPU version of virt/maddr conversion is simple since VA==PA. Signed-off-by: Penny Zheng Signed-off-by: Wei Chen Signed-off-by: Luca Fancellu Reviewed-by: Michal Orzel --- v3 changes: - Add Michal R-by v2 changes: - add missing headers, fix header protection macro name convention - take into account PADDR_MASK in virt_to_maddr - fixed typo in commit message - moved also maddr_to_virt to mmu/mm.h and moved include of mmu/mpu. - moved introduction of mm.c footer on commit that touches that file. --- xen/arch/arm/include/asm/mm.h | 64 +++++-------------------------- xen/arch/arm/include/asm/mmu/mm.h | 56 +++++++++++++++++++++++++++ xen/arch/arm/include/asm/mpu/mm.h | 27 +++++++++++++ 3 files changed, 92 insertions(+), 55 deletions(-) create mode 100644 xen/arch/arm/include/asm/mpu/mm.h diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index a0d8e5afe977..444fd03823ec 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -14,12 +14,6 @@ # error "unknown ARM variant" #endif -#if defined(CONFIG_MMU) -# include -#elif !defined(CONFIG_MPU) -# error "Unknown memory management layout" -#endif - /* Align Xen to a 2 MiB boundary. */ #define XEN_PADDR_ALIGN (1 << 21) @@ -261,55 +255,6 @@ static inline void __iomem *ioremap_wc(paddr_t start, size_t len) /* Page-align address and convert to frame number format */ #define paddr_to_pfn_aligned(paddr) paddr_to_pfn(PAGE_ALIGN(paddr)) -#define virt_to_maddr(va) ({ \ - vaddr_t va_ = (vaddr_t)(va); \ - (paddr_t)((va_to_par(va_) & PADDR_MASK & PAGE_MASK) | (va_ & ~PAGE_MASK)); \ -}) - -#ifdef CONFIG_ARM_32 -/** - * Find the virtual address corresponding to a machine address - * - * Only memory backing the XENHEAP has a corresponding virtual address to - * be found. This is so we can save precious virtual space, as it's in - * short supply on arm32. This mapping is not subject to PDX compression - * because XENHEAP is known to be physically contiguous and can't hence - * jump over the PDX hole. This means we can avoid the roundtrips - * converting to/from pdx. - * - * @param ma Machine address - * @return Virtual address mapped to `ma` - */ -static inline void *maddr_to_virt(paddr_t ma) -{ - ASSERT(is_xen_heap_mfn(maddr_to_mfn(ma))); - ma -= mfn_to_maddr(directmap_mfn_start); - return (void *)(unsigned long) ma + XENHEAP_VIRT_START; -} -#else -/** - * Find the virtual address corresponding to a machine address - * - * The directmap covers all conventional memory accesible by the - * hypervisor. This means it's subject to PDX compression. - * - * Note there's an extra offset applied (directmap_base_pdx) on top of the - * regular PDX compression logic. Its purpose is to skip over the initial - * range of non-existing memory, should there be one. - * - * @param ma Machine address - * @return Virtual address mapped to `ma` - */ -static inline void *maddr_to_virt(paddr_t ma) -{ - ASSERT((mfn_to_pdx(maddr_to_mfn(ma)) - directmap_base_pdx) < - (DIRECTMAP_SIZE >> PAGE_SHIFT)); - return (void *)(XENHEAP_VIRT_START - - (directmap_base_pdx << PAGE_SHIFT) + - maddr_to_directmapoff(ma)); -} -#endif - /* * Translate a guest virtual address to a machine address. * Return the fault information if the translation has failed else 0. @@ -340,6 +285,15 @@ static inline uint64_t gvirt_to_maddr(vaddr_t va, paddr_t *pa, #define virt_to_mfn(va) __virt_to_mfn(va) #define mfn_to_virt(mfn) __mfn_to_virt(mfn) +/* Memory management subsystem header placed here to see the above macros */ +#if defined(CONFIG_MMU) +# include +#elif defined(CONFIG_MPU) +# include +#else +#error "Unknown memory management layout" +#endif + /* Convert between Xen-heap virtual addresses and page-info structures. */ static inline struct page_info *virt_to_page(const void *v) { diff --git a/xen/arch/arm/include/asm/mmu/mm.h b/xen/arch/arm/include/asm/mmu/mm.h index f5a00558c47b..6737c3ede783 100644 --- a/xen/arch/arm/include/asm/mmu/mm.h +++ b/xen/arch/arm/include/asm/mmu/mm.h @@ -2,6 +2,13 @@ #ifndef __ARM_MMU_MM_H__ #define __ARM_MMU_MM_H__ +#include +#include +#include +#include +#include +#include + /* Non-boot CPUs use this to find the correct pagetables. */ extern uint64_t init_ttbr; @@ -14,6 +21,55 @@ extern unsigned long directmap_base_pdx; #define frame_table ((struct page_info *)FRAMETABLE_VIRT_START) +#define virt_to_maddr(va) ({ \ + vaddr_t va_ = (vaddr_t)(va); \ + (paddr_t)((va_to_par(va_) & PADDR_MASK & PAGE_MASK) | (va_ & ~PAGE_MASK)); \ +}) + +#ifdef CONFIG_ARM_32 +/** + * Find the virtual address corresponding to a machine address + * + * Only memory backing the XENHEAP has a corresponding virtual address to + * be found. This is so we can save precious virtual space, as it's in + * short supply on arm32. This mapping is not subject to PDX compression + * because XENHEAP is known to be physically contiguous and can't hence + * jump over the PDX hole. This means we can avoid the roundtrips + * converting to/from pdx. + * + * @param ma Machine address + * @return Virtual address mapped to `ma` + */ +static inline void *maddr_to_virt(paddr_t ma) +{ + ASSERT(is_xen_heap_mfn(maddr_to_mfn(ma))); + ma -= mfn_to_maddr(directmap_mfn_start); + return (void *)(unsigned long) ma + XENHEAP_VIRT_START; +} +#else +/** + * Find the virtual address corresponding to a machine address + * + * The directmap covers all conventional memory accesible by the + * hypervisor. This means it's subject to PDX compression. + * + * Note there's an extra offset applied (directmap_base_pdx) on top of the + * regular PDX compression logic. Its purpose is to skip over the initial + * range of non-existing memory, should there be one. + * + * @param ma Machine address + * @return Virtual address mapped to `ma` + */ +static inline void *maddr_to_virt(paddr_t ma) +{ + ASSERT((mfn_to_pdx(maddr_to_mfn(ma)) - directmap_base_pdx) < + (DIRECTMAP_SIZE >> PAGE_SHIFT)); + return (void *)(XENHEAP_VIRT_START - + (directmap_base_pdx << PAGE_SHIFT) + + maddr_to_directmapoff(ma)); +} +#endif + /* * Print a walk of a page table or p2m * diff --git a/xen/arch/arm/include/asm/mpu/mm.h b/xen/arch/arm/include/asm/mpu/mm.h new file mode 100644 index 000000000000..6cfd0f5cd2c2 --- /dev/null +++ b/xen/arch/arm/include/asm/mpu/mm.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ARM_MPU_MM_H__ +#define __ARM_MPU_MM_H__ + +#include +#include +#include + +#define virt_to_maddr(va) ((paddr_t)((vaddr_t)(va) & PADDR_MASK)) + +/* On MPU systems there is no translation, ma == va. */ +static inline void *maddr_to_virt(paddr_t ma) +{ + return _p(ma); +} + +#endif /* __ARM_MPU_MM_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ From patchwork Mon Mar 17 20:07:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 14019936 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 A624EC282EC for ; Mon, 17 Mar 2025 20:07:59 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.918086.1322838 (Exim 4.92) (envelope-from ) id 1tuGkR-0006Fq-GJ; Mon, 17 Mar 2025 20:07:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 918086.1322838; Mon, 17 Mar 2025 20:07: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 1tuGkR-0006Fj-Cs; Mon, 17 Mar 2025 20:07:43 +0000 Received: by outflank-mailman (input) for mailman id 918086; Mon, 17 Mar 2025 20:07:42 +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 1tuGkQ-00061d-Au for xen-devel@lists.xenproject.org; Mon, 17 Mar 2025 20:07:42 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 7b3c397a-036b-11f0-9aba-95dc52dad729; Mon, 17 Mar 2025 21:07:41 +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 B578022FA; Mon, 17 Mar 2025 13:07:49 -0700 (PDT) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E59263F63F; Mon, 17 Mar 2025 13:07:39 -0700 (PDT) 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: 7b3c397a-036b-11f0-9aba-95dc52dad729 From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v3 3/7] xen/arm: Introduce frame_table and virt_to_page Date: Mon, 17 Mar 2025 20:07:23 +0000 Message-Id: <20250317200727.798696-4-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317200727.798696-1-luca.fancellu@arm.com> References: <20250317200727.798696-1-luca.fancellu@arm.com> MIME-Version: 1.0 Introduce frame_table in order to provide the implementation of virt_to_page for MPU system, move the MMU variant in mmu/mm.h. Introduce FRAMETABLE_NR that is required for 'pdx_group_valid' in pdx.c, but leave the initialisation of the frame table to a later stage. Define FRAMETABLE_SIZE for MPU to support up to 1TB of ram at this stage, as the only current implementation of armv8-r aarch64, which is cortex R82, can support 1TB or 256TB (r82 TRM r3p1 ID_AA64MMFR0_EL1.PARange). Take the occasion to sort alphabetically the headers following the Xen code style and add the emacs footer in mpu/mm.c. Signed-off-by: Luca Fancellu Reviewed-by: Michal Orzel --- v3 changes: - Simplified MPU virt_to_page conversions (Michal suggested) - Mentioned r82 TRM source for frame table size (Michal) - Add Michal R-by v2 changes: - sorted headers in mm.c - modified commit message - moved virt_to_page to MMU and MPU - removed frametable_pdx_end, used mfn_valid --- xen/arch/arm/include/asm/mm.h | 14 -------------- xen/arch/arm/include/asm/mmu/mm.h | 14 ++++++++++++++ xen/arch/arm/include/asm/mpu/layout.h | 3 +++ xen/arch/arm/include/asm/mpu/mm.h | 14 ++++++++++++++ xen/arch/arm/mpu/mm.c | 14 +++++++++++++- 5 files changed, 44 insertions(+), 15 deletions(-) diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index 444fd03823ec..fbffaccef49b 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -294,20 +294,6 @@ static inline uint64_t gvirt_to_maddr(vaddr_t va, paddr_t *pa, #error "Unknown memory management layout" #endif -/* Convert between Xen-heap virtual addresses and page-info structures. */ -static inline struct page_info *virt_to_page(const void *v) -{ - unsigned long va = (unsigned long)v; - unsigned long pdx; - - ASSERT(va >= XENHEAP_VIRT_START); - ASSERT(va < directmap_virt_end); - - pdx = (va - XENHEAP_VIRT_START) >> PAGE_SHIFT; - pdx += mfn_to_pdx(directmap_mfn_start); - return frame_table + pdx - frametable_base_pdx; -} - static inline void *page_to_virt(const struct page_info *pg) { return mfn_to_virt(mfn_x(page_to_mfn(pg))); diff --git a/xen/arch/arm/include/asm/mmu/mm.h b/xen/arch/arm/include/asm/mmu/mm.h index 6737c3ede783..caba987edc85 100644 --- a/xen/arch/arm/include/asm/mmu/mm.h +++ b/xen/arch/arm/include/asm/mmu/mm.h @@ -70,6 +70,20 @@ static inline void *maddr_to_virt(paddr_t ma) } #endif +/* Convert between Xen-heap virtual addresses and page-info structures. */ +static inline struct page_info *virt_to_page(const void *v) +{ + unsigned long va = (unsigned long)v; + unsigned long pdx; + + ASSERT(va >= XENHEAP_VIRT_START); + ASSERT(va < directmap_virt_end); + + pdx = (va - XENHEAP_VIRT_START) >> PAGE_SHIFT; + pdx += mfn_to_pdx(directmap_mfn_start); + return frame_table + pdx - frametable_base_pdx; +} + /* * Print a walk of a page table or p2m * diff --git a/xen/arch/arm/include/asm/mpu/layout.h b/xen/arch/arm/include/asm/mpu/layout.h index 248e55f8882d..c331d1feaa84 100644 --- a/xen/arch/arm/include/asm/mpu/layout.h +++ b/xen/arch/arm/include/asm/mpu/layout.h @@ -3,6 +3,9 @@ #ifndef __ARM_MPU_LAYOUT_H__ #define __ARM_MPU_LAYOUT_H__ +#define FRAMETABLE_SIZE GB(16) +#define FRAMETABLE_NR (FRAMETABLE_SIZE / sizeof(*frame_table)) + #define XEN_START_ADDRESS CONFIG_XEN_START_ADDRESS /* diff --git a/xen/arch/arm/include/asm/mpu/mm.h b/xen/arch/arm/include/asm/mpu/mm.h index 6cfd0f5cd2c2..86f33d9836b7 100644 --- a/xen/arch/arm/include/asm/mpu/mm.h +++ b/xen/arch/arm/include/asm/mpu/mm.h @@ -3,9 +3,13 @@ #ifndef __ARM_MPU_MM_H__ #define __ARM_MPU_MM_H__ +#include #include #include #include +#include + +extern struct page_info *frame_table; #define virt_to_maddr(va) ((paddr_t)((vaddr_t)(va) & PADDR_MASK)) @@ -15,6 +19,16 @@ static inline void *maddr_to_virt(paddr_t ma) return _p(ma); } +/* Convert between virtual address to page-info structure. */ +static inline struct page_info *virt_to_page(const void *v) +{ + mfn_t mfn = _mfn(virt_to_mfn(v)); + + ASSERT(mfn_valid(mfn)); + + return mfn_to_page(mfn); +} + #endif /* __ARM_MPU_MM_H__ */ /* diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c index 0b8748e57598..3632011c1013 100644 --- a/xen/arch/arm/mpu/mm.c +++ b/xen/arch/arm/mpu/mm.c @@ -1,9 +1,12 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -#include #include +#include +#include #include +struct page_info *frame_table; + static void __init __maybe_unused build_assertions(void) { /* @@ -13,3 +16,12 @@ static void __init __maybe_unused build_assertions(void) */ BUILD_BUG_ON(PAGE_SIZE != SZ_4K); } + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ From patchwork Mon Mar 17 20:07:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 14019939 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 929FFC35FFC for ; Mon, 17 Mar 2025 20:08:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.918088.1322853 (Exim 4.92) (envelope-from ) id 1tuGkS-0006X9-WD; Mon, 17 Mar 2025 20:07:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 918088.1322853; Mon, 17 Mar 2025 20:07:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tuGkS-0006X0-SD; Mon, 17 Mar 2025 20:07:44 +0000 Received: by outflank-mailman (input) for mailman id 918088; Mon, 17 Mar 2025 20:07:43 +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 1tuGkR-00061d-2t for xen-devel@lists.xenproject.org; Mon, 17 Mar 2025 20:07:43 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 7bec24f2-036b-11f0-9aba-95dc52dad729; Mon, 17 Mar 2025 21:07:42 +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 0A1872573; Mon, 17 Mar 2025 13:07:51 -0700 (PDT) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3A0BB3F63F; Mon, 17 Mar 2025 13:07:41 -0700 (PDT) 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: 7bec24f2-036b-11f0-9aba-95dc52dad729 From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v3 4/7] arm/mpu: Kconfig symbols for MPU build Date: Mon, 17 Mar 2025 20:07:24 +0000 Message-Id: <20250317200727.798696-5-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317200727.798696-1-luca.fancellu@arm.com> References: <20250317200727.798696-1-luca.fancellu@arm.com> MIME-Version: 1.0 The MPU system requires static memory to work, select that when building this memory management subsystem. While there, provide a restriction for the ARM_EFI Kconfig parameter to be built only when !MPU, the EFI stub is not used as there are no implementation of UEFI services for armv8-r. Signed-off-by: Luca Fancellu Reviewed-by: Michal Orzel --- v3 changes: - No changes v2 changes: - clarified commit message about static memory - Add R-by Michal --- xen/arch/arm/Kconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index ffdff1f0a36c..5ac6ec0212d2 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -85,6 +85,7 @@ config MMU config MPU bool "MPU" if UNSUPPORTED + select STATIC_MEMORY help Memory Protection Unit (MPU). Select if you plan to run Xen on ARMv8-R systems supporting EL2. (UNSUPPORTED) @@ -102,7 +103,7 @@ config ACPI config ARM_EFI bool "UEFI boot service support" - depends on ARM_64 + depends on ARM_64 && !MPU default y help This option provides support for boot services through From patchwork Mon Mar 17 20:07:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 14019940 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 37548C35FF9 for ; Mon, 17 Mar 2025 20:08:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.918089.1322861 (Exim 4.92) (envelope-from ) id 1tuGkT-0006gx-FH; Mon, 17 Mar 2025 20:07:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 918089.1322861; Mon, 17 Mar 2025 20:07:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tuGkT-0006fG-Ac; Mon, 17 Mar 2025 20:07:45 +0000 Received: by outflank-mailman (input) for mailman id 918089; Mon, 17 Mar 2025 20:07:44 +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 1tuGkS-00061d-EK for xen-devel@lists.xenproject.org; Mon, 17 Mar 2025 20:07:44 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 7cb821c1-036b-11f0-9aba-95dc52dad729; Mon, 17 Mar 2025 21:07:43 +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 52DC925DC; Mon, 17 Mar 2025 13:07:52 -0700 (PDT) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 82C5F3F63F; Mon, 17 Mar 2025 13:07:42 -0700 (PDT) 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: 7cb821c1-036b-11f0-9aba-95dc52dad729 From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v3 5/7] arm/mpu: Implement stubs for ioremap_attr on MPU Date: Mon, 17 Mar 2025 20:07:25 +0000 Message-Id: <20250317200727.798696-6-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317200727.798696-1-luca.fancellu@arm.com> References: <20250317200727.798696-1-luca.fancellu@arm.com> MIME-Version: 1.0 Implement ioremap_attr() stub for MPU system; the implementation of ioremap() is the same between MMU and MPU system, and it relies on ioremap_attr(), so move the definition from mmu/pt.c to arm/mm.c. Signed-off-by: Luca Fancellu Reviewed-by: Michal Orzel --- v3 changes: - No changes v2 changes: - Add R-by Michal --- xen/arch/arm/mm.c | 5 +++++ xen/arch/arm/mmu/pt.c | 5 ----- xen/arch/arm/mpu/mm.c | 6 ++++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index a56e20ba2bdc..5a52f0c623e5 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -395,6 +395,11 @@ unsigned long get_upper_mfn_bound(void) return max_page - 1; } +void *ioremap(paddr_t pa, size_t len) +{ + return ioremap_attr(pa, len, PAGE_HYPERVISOR_NOCACHE); +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/mmu/pt.c b/xen/arch/arm/mmu/pt.c index da28d669e796..11cb1c66dac8 100644 --- a/xen/arch/arm/mmu/pt.c +++ b/xen/arch/arm/mmu/pt.c @@ -223,11 +223,6 @@ void *ioremap_attr(paddr_t start, size_t len, unsigned int attributes) return ptr + offs; } -void *ioremap(paddr_t pa, size_t len) -{ - return ioremap_attr(pa, len, PAGE_HYPERVISOR_NOCACHE); -} - static int create_xen_table(lpae_t *entry) { mfn_t mfn; diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c index 3632011c1013..4e9a2405d8c5 100644 --- a/xen/arch/arm/mpu/mm.c +++ b/xen/arch/arm/mpu/mm.c @@ -17,6 +17,12 @@ static void __init __maybe_unused build_assertions(void) BUILD_BUG_ON(PAGE_SIZE != SZ_4K); } +void __iomem *ioremap_attr(paddr_t start, size_t len, unsigned int flags) +{ + BUG_ON("unimplemented"); + return NULL; +} + /* * Local variables: * mode: C From patchwork Mon Mar 17 20:07:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 14019937 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 EA836C35FF8 for ; Mon, 17 Mar 2025 20:07:59 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.918091.1322877 (Exim 4.92) (envelope-from ) id 1tuGkX-0007GQ-Lw; Mon, 17 Mar 2025 20:07:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 918091.1322877; Mon, 17 Mar 2025 20:07: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 1tuGkX-0007GC-I8; Mon, 17 Mar 2025 20:07:49 +0000 Received: by outflank-mailman (input) for mailman id 918091; Mon, 17 Mar 2025 20:07:48 +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 1tuGkW-00063P-I3 for xen-devel@lists.xenproject.org; Mon, 17 Mar 2025 20:07:48 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 7e66b9d5-036b-11f0-9899-31a8f345e629; Mon, 17 Mar 2025 21:07:46 +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 0EF9B26BE; Mon, 17 Mar 2025 13:07:55 -0700 (PDT) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CD76F3F63F; Mon, 17 Mar 2025 13:07:43 -0700 (PDT) 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: 7e66b9d5-036b-11f0-9899-31a8f345e629 From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , Anthony PERARD , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Alistair Francis , Bob Eshleman , Connor Davis , Oleksii Kurochko , Penny Zheng , Wei Chen Subject: [PATCH v3 6/7] xen: introduce Kconfig ARCH_PAGING_MEMPOOL Date: Mon, 17 Mar 2025 20:07:26 +0000 Message-Id: <20250317200727.798696-7-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317200727.798696-1-luca.fancellu@arm.com> References: <20250317200727.798696-1-luca.fancellu@arm.com> MIME-Version: 1.0 From: Penny Zheng ARM MPU system doesn't need to use paging memory pool, as MPU memory mapping table at most takes only one 4KB page, which is enough to manage the maximum 255 MPU memory regions, for all EL2 stage 1 translation and EL1 stage 2 translation. Introduce ARCH_PAGING_MEMPOOL Kconfig common symbol, selected for Arm MMU systems, x86 and RISC-V. Wrap the code inside 'construct_domU' that deal with p2m paging allocation in a new function 'domain_p2m_set_allocation', protected by ARCH_PAGING_MEMPOOL, this is done in this way to prevent polluting the former function with #ifdefs and improve readability Introduce arch_{get,set}_paging_mempool_size stubs for architecture with !ARCH_PAGING_MEMPOOL. Remove 'struct paging_domain' from Arm 'struct arch_domain' when the field is not required. Signed-off-by: Penny Zheng Signed-off-by: Wei Chen Signed-off-by: Luca Fancellu Reviewed-by: Michal Orzel --- v3 changes: - Introduced ARCH_PAGING_MEMPOOL instead of HAS_PAGING_MEMPOOL v2 changes: - make Kconfig HAS_PAGING_MEMPOOL common - protect also "xen,domain-p2m-mem-mb" reading with HAS_PAGING_MEMPOOL - do not define p2m_teardown{_allocation} in this patch - change commit message --- xen/arch/arm/Kconfig | 1 + xen/arch/arm/dom0less-build.c | 74 ++++++++++++++++++++----------- xen/arch/arm/include/asm/domain.h | 2 + xen/arch/riscv/Kconfig | 1 + xen/arch/x86/Kconfig | 1 + xen/common/Kconfig | 3 ++ xen/include/xen/domain.h | 17 +++++++ 7 files changed, 73 insertions(+), 26 deletions(-) diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 5ac6ec0212d2..a4af0b85f158 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -75,6 +75,7 @@ choice config MMU bool "MMU" + select ARCH_PAGING_MEMPOOL select HAS_LLC_COLORING if !NUMA && ARM_64 select HAS_PMAP select HAS_VMAP diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index 573b0d25ae41..6eef6ba91444 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -673,21 +673,6 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo) return -EINVAL; } -static unsigned long __init domain_p2m_pages(unsigned long maxmem_kb, - unsigned int smp_cpus) -{ - /* - * Keep in sync with libxl__get_required_paging_memory(). - * 256 pages (1MB) per vcpu, plus 1 page per MiB of RAM for the P2M map, - * plus 128 pages to cover extended regions. - */ - unsigned long memkb = 4 * (256 * smp_cpus + (maxmem_kb / 1024) + 128); - - BUILD_BUG_ON(PAGE_SIZE != SZ_4K); - - return DIV_ROUND_UP(memkb, 1024) << (20 - PAGE_SHIFT); -} - static int __init alloc_xenstore_evtchn(struct domain *d) { evtchn_alloc_unbound_t alloc; @@ -841,6 +826,53 @@ static void __init domain_vcpu_affinity(struct domain *d, } } +#ifdef CONFIG_ARCH_PAGING_MEMPOOL + +static unsigned long __init domain_p2m_pages(unsigned long maxmem_kb, + unsigned int smp_cpus) +{ + /* + * Keep in sync with libxl__get_required_paging_memory(). + * 256 pages (1MB) per vcpu, plus 1 page per MiB of RAM for the P2M map, + * plus 128 pages to cover extended regions. + */ + unsigned long memkb = 4 * (256 * smp_cpus + (maxmem_kb / 1024) + 128); + + BUILD_BUG_ON(PAGE_SIZE != SZ_4K); + + return DIV_ROUND_UP(memkb, 1024) << (20 - PAGE_SHIFT); +} + +static int __init domain_p2m_set_allocation(struct domain *d, uint64_t mem, + const struct dt_device_node *node) +{ + unsigned long p2m_pages; + uint32_t p2m_mem_mb; + int rc; + + rc = dt_property_read_u32(node, "xen,domain-p2m-mem-mb", &p2m_mem_mb); + /* If xen,domain-p2m-mem-mb is not specified, use the default value. */ + p2m_pages = rc ? + p2m_mem_mb << (20 - PAGE_SHIFT) : + domain_p2m_pages(mem, d->max_vcpus); + + spin_lock(&d->arch.paging.lock); + rc = p2m_set_allocation(d, p2m_pages, NULL); + spin_unlock(&d->arch.paging.lock); + + return rc; +} + +#else /* !CONFIG_ARCH_PAGING_MEMPOOL */ + +static inline int domain_p2m_set_allocation(struct domain *d, uint64_t mem, + const struct dt_device_node *node) +{ + return 0; +} + +#endif /* CONFIG_ARCH_PAGING_MEMPOOL */ + static int __init construct_domU(struct domain *d, const struct dt_device_node *node) { @@ -848,8 +880,6 @@ static int __init construct_domU(struct domain *d, const char *dom0less_enhanced; int rc; u64 mem; - u32 p2m_mem_mb; - unsigned long p2m_pages; rc = dt_property_read_u64(node, "memory", &mem); if ( !rc ) @@ -859,15 +889,7 @@ static int __init construct_domU(struct domain *d, } kinfo.unassigned_mem = (paddr_t)mem * SZ_1K; - rc = dt_property_read_u32(node, "xen,domain-p2m-mem-mb", &p2m_mem_mb); - /* If xen,domain-p2m-mem-mb is not specified, use the default value. */ - p2m_pages = rc ? - p2m_mem_mb << (20 - PAGE_SHIFT) : - domain_p2m_pages(mem, d->max_vcpus); - - spin_lock(&d->arch.paging.lock); - rc = p2m_set_allocation(d, p2m_pages, NULL); - spin_unlock(&d->arch.paging.lock); + rc = domain_p2m_set_allocation(d, mem, node); if ( rc != 0 ) return rc; diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/domain.h index 50b6a4b00982..a3487ca71303 100644 --- a/xen/arch/arm/include/asm/domain.h +++ b/xen/arch/arm/include/asm/domain.h @@ -75,7 +75,9 @@ struct arch_domain struct hvm_domain hvm; +#ifdef CONFIG_ARCH_PAGING_MEMPOOL struct paging_domain paging; +#endif struct vmmio vmmio; diff --git a/xen/arch/riscv/Kconfig b/xen/arch/riscv/Kconfig index d882e0a0598d..1bd8ae16dc65 100644 --- a/xen/arch/riscv/Kconfig +++ b/xen/arch/riscv/Kconfig @@ -1,5 +1,6 @@ config RISCV def_bool y + select ARCH_PAGING_MEMPOOL select FUNCTION_ALIGNMENT_16B select GENERIC_BUG_FRAME select HAS_DEVICE_TREE diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index f08679959440..f6aa892661b4 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -9,6 +9,7 @@ config X86 select ACPI_NUMA select ALTERNATIVE_CALL select ARCH_MAP_DOMAIN_PAGE + select ARCH_PAGING_MEMPOOL select ARCH_SUPPORTS_INT128 imply CORE_PARKING select FUNCTION_ALIGNMENT_16B diff --git a/xen/common/Kconfig b/xen/common/Kconfig index a6aa2c5c1456..218357d593b7 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -44,6 +44,9 @@ config ALTERNATIVE_CALL config ARCH_MAP_DOMAIN_PAGE bool +config ARCH_PAGING_MEMPOOL + bool + config GENERIC_BUG_FRAME bool diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 83069de50118..a34daa7d10ab 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -2,6 +2,7 @@ #ifndef __XEN_DOMAIN_H__ #define __XEN_DOMAIN_H__ +#include #include #include @@ -114,9 +115,25 @@ void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c); int arch_initialise_vcpu(struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg); int default_initialise_vcpu(struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg); +#ifdef CONFIG_ARCH_PAGING_MEMPOOL + int arch_get_paging_mempool_size(struct domain *d, uint64_t *size /* bytes */); int arch_set_paging_mempool_size(struct domain *d, uint64_t size /* bytes */); +#else /* !CONFIG_ARCH_PAGING_MEMPOOL */ + +static inline int arch_get_paging_mempool_size(struct domain *d, uint64_t *size) +{ + return -EOPNOTSUPP; +} + +static inline int arch_set_paging_mempool_size(struct domain *d, uint64_t size) +{ + return -EOPNOTSUPP; +} + +#endif /* CONFIG_ARCH_PAGING_MEMPOOL */ + bool update_runstate_area(struct vcpu *v); int domain_relinquish_resources(struct domain *d); From patchwork Mon Mar 17 20:07:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 14019941 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 44240C35FFB for ; Mon, 17 Mar 2025 20:08:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.918093.1322888 (Exim 4.92) (envelope-from ) id 1tuGka-0007ar-0T; Mon, 17 Mar 2025 20:07:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 918093.1322888; Mon, 17 Mar 2025 20:07:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tuGkZ-0007ad-Rh; Mon, 17 Mar 2025 20:07:51 +0000 Received: by outflank-mailman (input) for mailman id 918093; Mon, 17 Mar 2025 20:07:50 +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 1tuGkY-00063P-84 for xen-devel@lists.xenproject.org; Mon, 17 Mar 2025 20:07:50 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 7f67dcc9-036b-11f0-9899-31a8f345e629; Mon, 17 Mar 2025 21:07:48 +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 76F6613D5; Mon, 17 Mar 2025 13:07:56 -0700 (PDT) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 877DC3F63F; Mon, 17 Mar 2025 13:07:46 -0700 (PDT) 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: 7f67dcc9-036b-11f0-9899-31a8f345e629 From: Luca Fancellu To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v3 7/7] arm/mpu: Create the skeleton for MPU compilation Date: Mon, 17 Mar 2025 20:07:27 +0000 Message-Id: <20250317200727.798696-8-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250317200727.798696-1-luca.fancellu@arm.com> References: <20250317200727.798696-1-luca.fancellu@arm.com> MIME-Version: 1.0 This commit introduces the skeleton for the MPU memory management subsystem that allows the compilation on Arm64. Signed-off-by: Luca Fancellu Reviewed-by: Michal Orzel --- The implementation of setup_virt_paging() is under arm64/mpu because it will have a different implementation from arm32. v3 changes: - rebase changes v2 changes: - p2m_teardown{_allocation} stubs are now part of this patch - included missing headers - rename vmap-mpu.c to vmap.c - remove comment "Not used on MPU system" on implemented stubs --- --- xen/arch/arm/arm64/mpu/Makefile | 2 + xen/arch/arm/arm64/mpu/p2m.c | 19 +++++++ xen/arch/arm/arm64/mpu/smpboot.c | 26 +++++++++ xen/arch/arm/include/asm/mpu/p2m.h | 21 ++++++++ xen/arch/arm/include/asm/p2m.h | 2 +- xen/arch/arm/mpu/Makefile | 3 ++ xen/arch/arm/mpu/mm.c | 25 +++++++++ xen/arch/arm/mpu/p2m.c | 84 ++++++++++++++++++++++++++++++ xen/arch/arm/mpu/setup.c | 40 ++++++++++++++ xen/arch/arm/mpu/vmap.c | 26 +++++++++ 10 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 xen/arch/arm/arm64/mpu/p2m.c create mode 100644 xen/arch/arm/arm64/mpu/smpboot.c create mode 100644 xen/arch/arm/include/asm/mpu/p2m.h create mode 100644 xen/arch/arm/mpu/p2m.c create mode 100644 xen/arch/arm/mpu/setup.c create mode 100644 xen/arch/arm/mpu/vmap.c diff --git a/xen/arch/arm/arm64/mpu/Makefile b/xen/arch/arm/arm64/mpu/Makefile index 3340058c08c6..cf0540aecc84 100644 --- a/xen/arch/arm/arm64/mpu/Makefile +++ b/xen/arch/arm/arm64/mpu/Makefile @@ -1 +1,3 @@ obj-y += head.o +obj-y += p2m.o +obj-y += smpboot.o diff --git a/xen/arch/arm/arm64/mpu/p2m.c b/xen/arch/arm/arm64/mpu/p2m.c new file mode 100644 index 000000000000..b6d8b2777b58 --- /dev/null +++ b/xen/arch/arm/arm64/mpu/p2m.c @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include +#include + +void __init setup_virt_paging(void) +{ + BUG_ON("unimplemented"); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/arm64/mpu/smpboot.c b/xen/arch/arm/arm64/mpu/smpboot.c new file mode 100644 index 000000000000..5090f443f577 --- /dev/null +++ b/xen/arch/arm/arm64/mpu/smpboot.c @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include +#include +#include + +int prepare_secondary_mm(int cpu) +{ + BUG_ON("unimplemented"); + return -EINVAL; +} + +void update_boot_mapping(bool enable) +{ + BUG_ON("unimplemented"); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/include/asm/mpu/p2m.h b/xen/arch/arm/include/asm/mpu/p2m.h new file mode 100644 index 000000000000..e46d9e757a1d --- /dev/null +++ b/xen/arch/arm/include/asm/mpu/p2m.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ARM_MPU_P2M_H__ +#define __ARM_MPU_P2M_H__ + +struct p2m_domain; + +static inline void p2m_clear_root_pages(struct p2m_domain *p2m) {} + +static inline void p2m_tlb_flush_sync(struct p2m_domain *p2m) {} + +#endif /* __ARM_MPU_P2M_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/include/asm/p2m.h b/xen/arch/arm/include/asm/p2m.h index 594dc4004138..2d53bf9b6177 100644 --- a/xen/arch/arm/include/asm/p2m.h +++ b/xen/arch/arm/include/asm/p2m.h @@ -168,7 +168,7 @@ typedef enum { #if defined(CONFIG_MMU) # include #else -# error "Unknown memory management layout" +# include #endif static inline bool arch_acquire_resource_check(struct domain *d) diff --git a/xen/arch/arm/mpu/Makefile b/xen/arch/arm/mpu/Makefile index b18cec483671..21bbc517b51a 100644 --- a/xen/arch/arm/mpu/Makefile +++ b/xen/arch/arm/mpu/Makefile @@ -1 +1,4 @@ obj-y += mm.o +obj-y += p2m.o +obj-y += setup.init.o +obj-y += vmap.o diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c index 4e9a2405d8c5..07c8959f4ee9 100644 --- a/xen/arch/arm/mpu/mm.c +++ b/xen/arch/arm/mpu/mm.c @@ -1,9 +1,12 @@ /* SPDX-License-Identifier: GPL-2.0-only */ +#include +#include #include #include #include #include +#include struct page_info *frame_table; @@ -17,6 +20,28 @@ static void __init __maybe_unused build_assertions(void) BUILD_BUG_ON(PAGE_SIZE != SZ_4K); } +void __init setup_mm(void) +{ + BUG_ON("unimplemented"); +} + +int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf) +{ + BUG_ON("unimplemented"); + return -EINVAL; +} + +void dump_hyp_walk(vaddr_t addr) +{ + BUG_ON("unimplemented"); +} + +/* Release all __init and __initdata ranges to be reused */ +void free_init_memory(void) +{ + BUG_ON("unimplemented"); +} + void __iomem *ioremap_attr(paddr_t start, size_t len, unsigned int flags) { BUG_ON("unimplemented"); diff --git a/xen/arch/arm/mpu/p2m.c b/xen/arch/arm/mpu/p2m.c new file mode 100644 index 000000000000..f7fb58ab6aa8 --- /dev/null +++ b/xen/arch/arm/mpu/p2m.c @@ -0,0 +1,84 @@ + +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include +#include +#include +#include +#include +#include + +int p2m_set_entry(struct p2m_domain *p2m, gfn_t sgfn, unsigned long nr, + mfn_t smfn, p2m_type_t t, p2m_access_t a) +{ + BUG_ON("unimplemented"); + return -EINVAL; +} + +mfn_t p2m_get_entry(struct p2m_domain *p2m, gfn_t gfn, p2m_type_t *t, + p2m_access_t *a, unsigned int *page_order, bool *valid) +{ + BUG_ON("unimplemented"); + return INVALID_MFN; +} + +void p2m_dump_info(struct domain *d) +{ + BUG_ON("unimplemented"); +} + +int p2m_init(struct domain *d) +{ + BUG_ON("unimplemented"); + return -EINVAL; +} + +void p2m_save_state(struct vcpu *p) +{ + BUG_ON("unimplemented"); +} + +void p2m_restore_state(struct vcpu *n) +{ + BUG_ON("unimplemented"); +} + +void p2m_final_teardown(struct domain *d) +{ + BUG_ON("unimplemented"); +} + +bool p2m_resolve_translation_fault(struct domain *d, gfn_t gfn) +{ + BUG_ON("unimplemented"); + return false; +} + +void p2m_flush_vm(struct vcpu *v) {} + +int relinquish_p2m_mapping(struct domain *d) +{ + return 0; +} + +void p2m_domain_creation_finished(struct domain *d) {} + +int p2m_teardown(struct domain *d) +{ + return 0; +} + +int p2m_teardown_allocation(struct domain *d) +{ + return 0; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/mpu/setup.c b/xen/arch/arm/mpu/setup.c new file mode 100644 index 000000000000..b4da77003f47 --- /dev/null +++ b/xen/arch/arm/mpu/setup.c @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include +#include +#include +#include + +void __init setup_pagetables(void) {} + +void * __init early_fdt_map(paddr_t fdt_paddr) +{ + BUG_ON("unimplemented"); + return NULL; +} + +/* + * copy_from_paddr - copy data from a physical address + * @dst: destination virtual address + * @paddr: source physical address + * @len: length to copy + */ +void __init copy_from_paddr(void *dst, paddr_t paddr, unsigned long len) +{ + BUG_ON("unimplemented"); +} + +void __init remove_early_mappings(void) +{ + BUG_ON("unimplemented"); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/mpu/vmap.c b/xen/arch/arm/mpu/vmap.c new file mode 100644 index 000000000000..f977b79cd436 --- /dev/null +++ b/xen/arch/arm/mpu/vmap.c @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include +#include +#include + +void *vmap_contig(mfn_t mfn, unsigned int nr) +{ + BUG_ON("unimplemented"); + return NULL; +} + +void vunmap(const void *va) +{ + BUG_ON("unimplemented"); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */