From patchwork Thu May 2 16:55:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlo Nonato X-Patchwork-Id: 13651902 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 4C2F8C25B10 for ; Thu, 2 May 2024 16:56:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.715957.1118029 (Exim 4.92) (envelope-from ) id 1s2Ziq-0000bD-1T; Thu, 02 May 2024 16:55:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 715957.1118029; Thu, 02 May 2024 16:55: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 1s2Zip-0000ZI-Je; Thu, 02 May 2024 16:55:51 +0000 Received: by outflank-mailman (input) for mailman id 715957; Thu, 02 May 2024 16:55:49 +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 1s2Zin-0006N3-Oz for xen-devel@lists.xenproject.org; Thu, 02 May 2024 16:55:49 +0000 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [2a00:1450:4864:20::629]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d2f792ba-08a4-11ef-b4bb-af5377834399; Thu, 02 May 2024 18:55:48 +0200 (CEST) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a595c61553cso245322166b.1 for ; Thu, 02 May 2024 09:55:48 -0700 (PDT) Received: from carlo-ubuntu.mo54.unimo.it (nonato.mo54.unimo.it. [155.185.85.8]) by smtp.gmail.com with ESMTPSA id mq30-20020a170907831e00b00a5987fbfb83sm29103ejc.152.2024.05.02.09.55.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 09:55: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: d2f792ba-08a4-11ef-b4bb-af5377834399 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minervasys-tech.20230601.gappssmtp.com; s=20230601; t=1714668947; x=1715273747; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=js2dKSvePAqOWBjeqArRJcnowTogkyqLrYPgrRYmXag=; b=RRXcZgWPMNtOTswwIbUkP7F+MWzCBWMztxI3r820+EGbYvBRm2BOB945+xFe3uMGJd RuQ+1ba75qFq+90sqIv/VU3LijYiEKPfikMRiExZ0P+ySe5C3oR4ykYSnVT6FnTmhA3i VmrGVC3SAwhBRgkPP62xIYv/W7Uu+umMIxo3DzrjPH6ck+0ZF6BRlRwSEoz48yULKmm6 tqj2dtNz5fM2nHKpyvgr8OkUlntuHQXEUmkmQX3IoJ3Eyn60nXIWkzj3DeqIzxjl+OiF 1VE+A0gdixMuVkYoqr0bZfd3ZGmUh933f6Xduv0fB8cd/Zc9J7KS+/0eL0aIIMdJMPra n4Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714668947; x=1715273747; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=js2dKSvePAqOWBjeqArRJcnowTogkyqLrYPgrRYmXag=; b=TlOPt6rjg5t72vDLtsL7o+Faro/eQF0x2mhXdIZuBy3AE5ky8oF7RtqZCbBrKrB3GY F12r5GSZ1ClN3CipXsJuKcuNdxyAdBmv0HQJKxDCQeidd0A3O+Dvb4RK4u1uwmrMxeFS LVPm0JshHa0iv8k5c6IaeDTXVoVD1lAp8aJAscip3rqfxc7stIGE+gqjkGc0clipEcLl Y6WEv6TsY3iW1PTIDnWEUegEnQ1BTSfhUOLnwSqnUfKDwW6f5OrEYdQR1P16L7FlQgpk LTaxY3dWowC9KNk9OJLrFXcAA7POTdAtVVKZp9Pvn7fTcROCj2NcLedaSQwJUHOg+vpn Suuw== X-Gm-Message-State: AOJu0YyXLAwjEkBhtFCn6pvQwmdG0NM/VmTqbi+M8wY4sH4csOiA09mp uPM9hp+A1/WiDfojJkKGIWJ2C2K5RKJsSJm2GJVYvOYoc18x/x1LsXRF1rNKLaFK/VgObsZexlQ W X-Google-Smtp-Source: AGHT+IHgyNFFlUmdIrnd/ng6aOPddiEn0HB2PTkDujnG/vTVRVBCqMLVj1yOyJ1Lyw3K+l8ARC4uGg== X-Received: by 2002:a17:906:fcc3:b0:a59:7766:e4ed with SMTP id qx3-20020a170906fcc300b00a597766e4edmr70061ejb.32.1714668947016; Thu, 02 May 2024 09:55:47 -0700 (PDT) From: Carlo Nonato To: xen-devel@lists.xenproject.org Cc: andrea.bastoni@minervasys.tech, Carlo Nonato , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v8 12/13] xen/arm: make consider_modules() available for xen relocation Date: Thu, 2 May 2024 18:55:32 +0200 Message-Id: <20240502165533.319988-13-carlo.nonato@minervasys.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240502165533.319988-1-carlo.nonato@minervasys.tech> References: <20240502165533.319988-1-carlo.nonato@minervasys.tech> MIME-Version: 1.0 Cache coloring must physically relocate Xen in order to color the hypervisor and consider_modules() is a key function that is needed to find a new available physical address. 672d67f339c0 ("xen/arm: Split MMU-specific setup_mm() and related code out") moved consider_modules() under arm32. Move it to mmu/setup.c and make it non-static so that it can be used outside. Signed-off-by: Carlo Nonato --- v8: - patch adapted to new changes to consider_modules() v7: - moved consider_modules() to arm/mmu/setup.c v6: - new patch --- xen/arch/arm/arm32/mmu/mm.c | 115 +----------------------------- xen/arch/arm/include/asm/setup.h | 3 + xen/arch/arm/mmu/setup.c | 117 +++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 114 deletions(-) diff --git a/xen/arch/arm/arm32/mmu/mm.c b/xen/arch/arm/arm32/mmu/mm.c index 23150122f7..5d50db32eb 100644 --- a/xen/arch/arm/arm32/mmu/mm.c +++ b/xen/arch/arm/arm32/mmu/mm.c @@ -9,6 +9,7 @@ #include #include #include +#include static unsigned long opt_xenheap_megabytes __initdata; integer_param("xenheap_megabytes", opt_xenheap_megabytes); @@ -31,120 +32,6 @@ static void __init setup_directmap_mappings(unsigned long base_mfn, directmap_virt_end = XENHEAP_VIRT_START + nr_mfns * PAGE_SIZE; } -/* - * Returns the end address of the highest region in the range s..e - * with required size and alignment that does not conflict with the - * modules from first_mod to nr_modules. - * - * For non-recursive callers first_mod should normally be 0 (all - * modules and Xen itself) or 1 (all modules but not Xen). - */ -static paddr_t __init consider_modules(paddr_t s, paddr_t e, - uint32_t size, paddr_t align, - int first_mod) -{ - const struct membanks *reserved_mem = bootinfo_get_reserved_mem(); -#ifdef CONFIG_STATIC_SHM - const struct membanks *shmem = bootinfo_get_shmem(); -#endif - const struct bootmodules *mi = &bootinfo.modules; - int i; - int nr; - - s = (s+align-1) & ~(align-1); - e = e & ~(align-1); - - if ( s > e || e - s < size ) - return 0; - - /* First check the boot modules */ - for ( i = first_mod; i < mi->nr_mods; i++ ) - { - paddr_t mod_s = mi->module[i].start; - paddr_t mod_e = mod_s + mi->module[i].size; - - if ( s < mod_e && mod_s < e ) - { - mod_e = consider_modules(mod_e, e, size, align, i+1); - if ( mod_e ) - return mod_e; - - return consider_modules(s, mod_s, size, align, i+1); - } - } - - /* Now check any fdt reserved areas. */ - - nr = fdt_num_mem_rsv(device_tree_flattened); - - for ( ; i < mi->nr_mods + nr; i++ ) - { - paddr_t mod_s, mod_e; - - if ( fdt_get_mem_rsv_paddr(device_tree_flattened, - i - mi->nr_mods, - &mod_s, &mod_e ) < 0 ) - /* If we can't read it, pretend it doesn't exist... */ - continue; - - /* fdt_get_mem_rsv_paddr returns length */ - mod_e += mod_s; - - if ( s < mod_e && mod_s < e ) - { - mod_e = consider_modules(mod_e, e, size, align, i+1); - if ( mod_e ) - return mod_e; - - return consider_modules(s, mod_s, size, align, i+1); - } - } - - /* - * i is the current bootmodule we are evaluating, across all - * possible kinds of bootmodules. - * - * When retrieving the corresponding reserved-memory addresses, we - * need to index the reserved_mem bank starting from 0, and only counting - * the reserved-memory modules. Hence, we need to use i - nr. - */ - nr += mi->nr_mods; - for ( ; i - nr < reserved_mem->nr_banks; i++ ) - { - paddr_t r_s = reserved_mem->bank[i - nr].start; - paddr_t r_e = r_s + reserved_mem->bank[i - nr].size; - - if ( s < r_e && r_s < e ) - { - r_e = consider_modules(r_e, e, size, align, i + 1); - if ( r_e ) - return r_e; - - return consider_modules(s, r_s, size, align, i + 1); - } - } - -#ifdef CONFIG_STATIC_SHM - nr += reserved_mem->nr_banks; - for ( ; i - nr < shmem->nr_banks; i++ ) - { - paddr_t r_s = shmem->bank[i - nr].start; - paddr_t r_e = r_s + shmem->bank[i - nr].size; - - if ( s < r_e && r_s < e ) - { - r_e = consider_modules(r_e, e, size, align, i + 1); - if ( r_e ) - return r_e; - - return consider_modules(s, r_s, size, align, i + 1); - } - } -#endif - - return e; -} - /* * Find a contiguous region that fits in the static heap region with * required size and alignment, and return the end address of the region diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/setup.h index 28fb659fe9..a72b6d5c63 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -278,6 +278,9 @@ struct init_info unsigned int cpuid; }; +paddr_t consider_modules(paddr_t s, paddr_t e, uint32_t size, paddr_t align, + int first_mod); + #endif /* * Local variables: diff --git a/xen/arch/arm/mmu/setup.c b/xen/arch/arm/mmu/setup.c index f4bb424c3c..a8f93d4f82 100644 --- a/xen/arch/arm/mmu/setup.c +++ b/xen/arch/arm/mmu/setup.c @@ -6,7 +6,10 @@ */ #include +#include #include +#include +#include #include #include #include @@ -218,6 +221,120 @@ static void xen_pt_enforce_wnx(void) flush_xen_tlb_local(); } +/* + * Returns the end address of the highest region in the range s..e + * with required size and alignment that does not conflict with the + * modules from first_mod to nr_modules. + * + * For non-recursive callers first_mod should normally be 0 (all + * modules and Xen itself) or 1 (all modules but not Xen). + */ +paddr_t __init consider_modules(paddr_t s, paddr_t e, + uint32_t size, paddr_t align, + int first_mod) +{ + const struct membanks *reserved_mem = bootinfo_get_reserved_mem(); +#ifdef CONFIG_STATIC_SHM + const struct membanks *shmem = bootinfo_get_shmem(); +#endif + const struct bootmodules *mi = &bootinfo.modules; + int i; + int nr; + + s = (s+align-1) & ~(align-1); + e = e & ~(align-1); + + if ( s > e || e - s < size ) + return 0; + + /* First check the boot modules */ + for ( i = first_mod; i < mi->nr_mods; i++ ) + { + paddr_t mod_s = mi->module[i].start; + paddr_t mod_e = mod_s + mi->module[i].size; + + if ( s < mod_e && mod_s < e ) + { + mod_e = consider_modules(mod_e, e, size, align, i+1); + if ( mod_e ) + return mod_e; + + return consider_modules(s, mod_s, size, align, i+1); + } + } + + /* Now check any fdt reserved areas. */ + + nr = fdt_num_mem_rsv(device_tree_flattened); + + for ( ; i < mi->nr_mods + nr; i++ ) + { + paddr_t mod_s, mod_e; + + if ( fdt_get_mem_rsv_paddr(device_tree_flattened, + i - mi->nr_mods, + &mod_s, &mod_e ) < 0 ) + /* If we can't read it, pretend it doesn't exist... */ + continue; + + /* fdt_get_mem_rsv_paddr returns length */ + mod_e += mod_s; + + if ( s < mod_e && mod_s < e ) + { + mod_e = consider_modules(mod_e, e, size, align, i+1); + if ( mod_e ) + return mod_e; + + return consider_modules(s, mod_s, size, align, i+1); + } + } + + /* + * i is the current bootmodule we are evaluating, across all + * possible kinds of bootmodules. + * + * When retrieving the corresponding reserved-memory addresses, we + * need to index the reserved_mem bank starting from 0, and only counting + * the reserved-memory modules. Hence, we need to use i - nr. + */ + nr += mi->nr_mods; + for ( ; i - nr < reserved_mem->nr_banks; i++ ) + { + paddr_t r_s = reserved_mem->bank[i - nr].start; + paddr_t r_e = r_s + reserved_mem->bank[i - nr].size; + + if ( s < r_e && r_s < e ) + { + r_e = consider_modules(r_e, e, size, align, i + 1); + if ( r_e ) + return r_e; + + return consider_modules(s, r_s, size, align, i + 1); + } + } + +#ifdef CONFIG_STATIC_SHM + nr += reserved_mem->nr_banks; + for ( ; i - nr < shmem->nr_banks; i++ ) + { + paddr_t r_s = shmem->bank[i - nr].start; + paddr_t r_e = r_s + shmem->bank[i - nr].size; + + if ( s < r_e && r_s < e ) + { + r_e = consider_modules(r_e, e, size, align, i + 1); + if ( r_e ) + return r_e; + + return consider_modules(s, r_s, size, align, i + 1); + } + } +#endif + + return e; +} + /* * Boot-time pagetable setup. * Changes here may need matching changes in head.S