From patchwork Sun Mar 16 19:24:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 14018523 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 0DDABC35FFA for ; Sun, 16 Mar 2025 19:25:53 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.916071.1321269 (Exim 4.92) (envelope-from ) id 1tttc8-0005KX-QW; Sun, 16 Mar 2025 19:25:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 916071.1321269; Sun, 16 Mar 2025 19:25:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tttc8-0005KO-MU; Sun, 16 Mar 2025 19:25:36 +0000 Received: by outflank-mailman (input) for mailman id 916071; Sun, 16 Mar 2025 19:25:34 +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 1tttc6-0004Ab-J3 for xen-devel@lists.xenproject.org; Sun, 16 Mar 2025 19:25:34 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 6a6b7ebb-029c-11f0-9aba-95dc52dad729; Sun, 16 Mar 2025 20:25:27 +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 6EF17153B; Sun, 16 Mar 2025 12:25:36 -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 30E9F3F694; Sun, 16 Mar 2025 12:25:26 -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: 6a6b7ebb-029c-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 v2 1/7] arm/mpu: Add HYPERVISOR_VIRT_START and avoid a check in xen.lds.S Date: Sun, 16 Mar 2025 19:24:39 +0000 Message-Id: <20250316192445.2376484-2-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250316192445.2376484-1-luca.fancellu@arm.com> References: <20250316192445.2376484-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 --- 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 Sun Mar 16 19:24:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 14018524 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 BCB25C35FF8 for ; Sun, 16 Mar 2025 19:25:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.916067.1321224 (Exim 4.92) (envelope-from ) id 1tttc4-0004Bu-TE; Sun, 16 Mar 2025 19:25:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 916067.1321224; Sun, 16 Mar 2025 19:25:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tttc4-0004BL-Lv; Sun, 16 Mar 2025 19:25:32 +0000 Received: by outflank-mailman (input) for mailman id 916067; Sun, 16 Mar 2025 19:25:31 +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 1tttc2-0004Ab-Vn for xen-devel@lists.xenproject.org; Sun, 16 Mar 2025 19:25:30 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 6b5511c0-029c-11f0-9aba-95dc52dad729; Sun, 16 Mar 2025 20:25:29 +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 034241A32; Sun, 16 Mar 2025 12:25:38 -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 751883F694; Sun, 16 Mar 2025 12:25:27 -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: 6b5511c0-029c-11f0-9aba-95dc52dad729 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 v2 2/7] xen/arm: Implement virt/maddr conversion in MPU system Date: Sun, 16 Mar 2025 19:24:40 +0000 Message-Id: <20250316192445.2376484-3-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250316192445.2376484-1-luca.fancellu@arm.com> References: <20250316192445.2376484-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 --- 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 Sun Mar 16 19:24:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 14018522 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 258F3C282DE for ; Sun, 16 Mar 2025 19:25:51 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.916068.1321228 (Exim 4.92) (envelope-from ) id 1tttc5-0004Ge-56; Sun, 16 Mar 2025 19:25:33 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 916068.1321228; Sun, 16 Mar 2025 19:25:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tttc4-0004FF-Vi; Sun, 16 Mar 2025 19:25:32 +0000 Received: by outflank-mailman (input) for mailman id 916068; Sun, 16 Mar 2025 19:25:31 +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 1tttc3-0004Ab-IC for xen-devel@lists.xenproject.org; Sun, 16 Mar 2025 19:25:31 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 6bfe6a78-029c-11f0-9aba-95dc52dad729; Sun, 16 Mar 2025 20:25:29 +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 46B5F1D34; Sun, 16 Mar 2025 12:25:39 -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 215313F694; Sun, 16 Mar 2025 12:25:29 -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: 6bfe6a78-029c-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 v2 3/7] xen/arm: Introduce frame_table and virt_to_page Date: Sun, 16 Mar 2025 19:24:41 +0000 Message-Id: <20250316192445.2376484-4-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250316192445.2376484-1-luca.fancellu@arm.com> References: <20250316192445.2376484-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, as the only current implementation of armv8-r aarch64, which is cortex R82, can address up to that memory. 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 --- 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 | 15 +++++++++++++++ xen/arch/arm/mpu/mm.c | 14 +++++++++++++- 5 files changed, 45 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..3a0a60dbfa18 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,17 @@ 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) +{ + paddr_t paddr = virt_to_maddr(v); + unsigned long pdx = paddr_to_pdx(paddr); + + ASSERT(mfn_valid(maddr_to_mfn(paddr))); + + return frame_table + pdx - frametable_base_pdx; +} + #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 Sun Mar 16 19:24:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 14018517 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 2A151C3DA4A for ; Sun, 16 Mar 2025 19:25:51 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.916069.1321249 (Exim 4.92) (envelope-from ) id 1tttc6-0004qU-Cw; Sun, 16 Mar 2025 19:25:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 916069.1321249; Sun, 16 Mar 2025 19:25:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tttc6-0004pu-8h; Sun, 16 Mar 2025 19:25:34 +0000 Received: by outflank-mailman (input) for mailman id 916069; Sun, 16 Mar 2025 19:25:32 +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 1tttc4-0004Ab-IV for xen-devel@lists.xenproject.org; Sun, 16 Mar 2025 19:25:32 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 6cbd3fab-029c-11f0-9aba-95dc52dad729; Sun, 16 Mar 2025 20:25:31 +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 899C21D6F; Sun, 16 Mar 2025 12:25:40 -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 645D53F694; Sun, 16 Mar 2025 12:25:30 -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: 6cbd3fab-029c-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 v2 4/7] arm/mpu: Kconfig symbols for MPU build Date: Sun, 16 Mar 2025 19:24:42 +0000 Message-Id: <20250316192445.2376484-5-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250316192445.2376484-1-luca.fancellu@arm.com> References: <20250316192445.2376484-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 --- 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 Sun Mar 16 19:24:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 14018519 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 CE30DC35FF6 for ; Sun, 16 Mar 2025 19:25:51 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.916070.1321252 (Exim 4.92) (envelope-from ) id 1tttc6-0004se-KG; Sun, 16 Mar 2025 19:25:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 916070.1321252; Sun, 16 Mar 2025 19:25:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tttc6-0004rI-F2; Sun, 16 Mar 2025 19:25:34 +0000 Received: by outflank-mailman (input) for mailman id 916070; Sun, 16 Mar 2025 19:25:33 +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 1tttc5-0004Ab-Il for xen-devel@lists.xenproject.org; Sun, 16 Mar 2025 19:25:33 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 6d85e90a-029c-11f0-9aba-95dc52dad729; Sun, 16 Mar 2025 20:25:32 +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 CCF6D2437; Sun, 16 Mar 2025 12:25:41 -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 A78683F694; Sun, 16 Mar 2025 12:25:31 -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: 6d85e90a-029c-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 v2 5/7] arm/mpu: Implement stubs for ioremap_attr on MPU Date: Sun, 16 Mar 2025 19:24:43 +0000 Message-Id: <20250316192445.2376484-6-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250316192445.2376484-1-luca.fancellu@arm.com> References: <20250316192445.2376484-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 --- 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 Sun Mar 16 19:24:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 14018520 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 DD193C35FF7 for ; Sun, 16 Mar 2025 19:25:51 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.916073.1321282 (Exim 4.92) (envelope-from ) id 1tttcB-0005hW-HM; Sun, 16 Mar 2025 19:25:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 916073.1321282; Sun, 16 Mar 2025 19:25:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tttcB-0005gT-C0; Sun, 16 Mar 2025 19:25:39 +0000 Received: by outflank-mailman (input) for mailman id 916073; Sun, 16 Mar 2025 19:25:37 +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 1tttc9-0005Uc-Ng for xen-devel@lists.xenproject.org; Sun, 16 Mar 2025 19:25:37 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 6f3d15a9-029c-11f0-9899-31a8f345e629; Sun, 16 Mar 2025 20:25:35 +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 1D10B2573; Sun, 16 Mar 2025 12:25:44 -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 EC7F43F694; Sun, 16 Mar 2025 12:25:32 -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: 6f3d15a9-029c-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?= , Penny Zheng , Wei Chen Subject: [PATCH v2 6/7] xen: introduce Kconfig HAS_PAGING_MEMPOOL Date: Sun, 16 Mar 2025 19:24:44 +0000 Message-Id: <20250316192445.2376484-7-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250316192445.2376484-1-luca.fancellu@arm.com> References: <20250316192445.2376484-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 HAS_PAGING_MEMPOOL Kconfig common symbol, selected for Arm MMU systems. Wrap the code inside 'construct_domU' that deal with p2m paging allocation in a new function 'domu_p2m_set_allocation', protected by HAS_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 implementation for MPU system. 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 --- 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 | 48 ++++++++++++++++++++++++------- xen/arch/arm/include/asm/domain.h | 2 ++ xen/arch/arm/mpu/Makefile | 1 + xen/arch/arm/mpu/p2m.c | 25 ++++++++++++++++ xen/common/Kconfig | 3 ++ 6 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 xen/arch/arm/mpu/p2m.c diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 5ac6ec0212d2..6b4bcf12683e 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -76,6 +76,7 @@ choice config MMU bool "MMU" select HAS_LLC_COLORING if !NUMA && ARM_64 + select HAS_PAGING_MEMPOOL select HAS_PMAP select HAS_VMAP select HAS_PASSTHROUGH diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index 573b0d25ae41..a65bbbb05301 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -673,6 +673,8 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo) return -EINVAL; } +#ifdef CONFIG_HAS_PAGING_MEMPOOL + static unsigned long __init domain_p2m_pages(unsigned long maxmem_kb, unsigned int smp_cpus) { @@ -688,6 +690,8 @@ static unsigned long __init domain_p2m_pages(unsigned long maxmem_kb, return DIV_ROUND_UP(memkb, 1024) << (20 - PAGE_SHIFT); } +#endif + static int __init alloc_xenstore_evtchn(struct domain *d) { evtchn_alloc_unbound_t alloc; @@ -841,6 +845,38 @@ static void __init domain_vcpu_affinity(struct domain *d, } } +#ifdef CONFIG_HAS_PAGING_MEMPOOL + +static int __init domu_p2m_set_allocation(struct domain *d, u64 mem, + const struct dt_device_node *node) +{ + unsigned long p2m_pages; + u32 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_HAS_PAGING_MEMPOOL */ + +static inline int domu_p2m_set_allocation(struct domain *d, u64 mem, + const struct dt_device_node *node) +{ + return 0; +} + +#endif /* CONFIG_HAS_PAGING_MEMPOOL */ + static int __init construct_domU(struct domain *d, const struct dt_device_node *node) { @@ -848,8 +884,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 +893,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 = domu_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..fadec7d8fa9e 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_HAS_PAGING_MEMPOOL struct paging_domain paging; +#endif struct vmmio vmmio; diff --git a/xen/arch/arm/mpu/Makefile b/xen/arch/arm/mpu/Makefile index b18cec483671..5424ab6239c8 100644 --- a/xen/arch/arm/mpu/Makefile +++ b/xen/arch/arm/mpu/Makefile @@ -1 +1,2 @@ obj-y += mm.o +obj-y += p2m.o diff --git a/xen/arch/arm/mpu/p2m.c b/xen/arch/arm/mpu/p2m.c new file mode 100644 index 000000000000..71f9cdbf2fdb --- /dev/null +++ b/xen/arch/arm/mpu/p2m.c @@ -0,0 +1,25 @@ + +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include +#include + +int arch_get_paging_mempool_size(struct domain *d, uint64_t *size) +{ + return -EOPNOTSUPP; +} + +int arch_set_paging_mempool_size(struct domain *d, uint64_t size) +{ + return -EOPNOTSUPP; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 6166327f4d14..a3bdf546d02f 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -74,6 +74,9 @@ config HAS_KEXEC config HAS_LLC_COLORING bool +config HAS_PAGING_MEMPOOL + bool + config HAS_PIRQ bool From patchwork Sun Mar 16 19:24:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 14018518 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 27CA8C28B30 for ; Sun, 16 Mar 2025 19:25:51 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.916072.1321280 (Exim 4.92) (envelope-from ) id 1tttcB-0005d1-8v; Sun, 16 Mar 2025 19:25:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 916072.1321280; Sun, 16 Mar 2025 19:25:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tttcB-0005cs-42; Sun, 16 Mar 2025 19:25:39 +0000 Received: by outflank-mailman (input) for mailman id 916072; Sun, 16 Mar 2025 19:25:37 +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 1tttc9-0004Ab-MC for xen-devel@lists.xenproject.org; Sun, 16 Mar 2025 19:25:37 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 6fb61cc2-029c-11f0-9aba-95dc52dad729; Sun, 16 Mar 2025 20:25:36 +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 6482012FC; Sun, 16 Mar 2025 12:25:45 -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 2070A3F694; Sun, 16 Mar 2025 12:25:35 -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: 6fb61cc2-029c-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 v2 7/7] arm/mpu: Create the skeleton for MPU compilation Date: Sun, 16 Mar 2025 19:24:45 +0000 Message-Id: <20250316192445.2376484-8-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250316192445.2376484-1-luca.fancellu@arm.com> References: <20250316192445.2376484-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 --- The implementation of setup_virt_paging() is under arm64/mpu because it will have a different implementation from arm32. 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 | 2 + xen/arch/arm/mpu/mm.c | 25 +++++++++++ xen/arch/arm/mpu/p2m.c | 69 ++++++++++++++++++++++++++++++ xen/arch/arm/mpu/setup.c | 40 +++++++++++++++++ xen/arch/arm/mpu/vmap.c | 26 +++++++++++ 10 files changed, 231 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/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 5424ab6239c8..21bbc517b51a 100644 --- a/xen/arch/arm/mpu/Makefile +++ b/xen/arch/arm/mpu/Makefile @@ -1,2 +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 index 71f9cdbf2fdb..f464c74f3288 100644 --- a/xen/arch/arm/mpu/p2m.c +++ b/xen/arch/arm/mpu/p2m.c @@ -1,9 +1,78 @@ /* 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; +} int arch_get_paging_mempool_size(struct domain *d, uint64_t *size) { 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: + */