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: + */