From patchwork Fri Mar 4 17:46:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Solieri X-Patchwork-Id: 12769767 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 4C378C433EF for ; Fri, 4 Mar 2022 18:18:13 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.284478.483998 (Exim 4.92) (envelope-from ) id 1nQCV6-0007vh-9t; Fri, 04 Mar 2022 18:18:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 284478.483998; Fri, 04 Mar 2022 18:17:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nQCV4-0007np-MY; Fri, 04 Mar 2022 18:17:58 +0000 Received: by outflank-mailman (input) for mailman id 284478; Fri, 04 Mar 2022 17:56:14 +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 1nQC2H-0005R5-Rt for xen-devel@lists.xenproject.org; Fri, 04 Mar 2022 17:48:13 +0000 Received: from radon.xt3.it (radon.xt3.it [2a01:4f8:190:4055::2]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 433b3b5c-9be3-11ec-8539-5f4723681683; Fri, 04 Mar 2022 18:48:13 +0100 (CET) Received: from nb2assolieri.mat.unimo.it ([155.185.4.56] helo=localhost) by radon.xt3.it with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1nQC2G-0000AI-G5; Fri, 04 Mar 2022 18:48:12 +0100 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: 433b3b5c-9be3-11ec-8539-5f4723681683 From: Marco Solieri To: xen-devel@lists.xenproject.org Cc: Marco Solieri , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Marco Solieri , Andrea Bastoni , Luca Miccio , Stefano Stabellini Subject: [PATCH 25/36] xen/arm: bring back get_xen_paddr Date: Fri, 4 Mar 2022 18:46:50 +0100 Message-Id: <20220304174701.1453977-26-marco.solieri@minervasys.tech> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220304174701.1453977-1-marco.solieri@minervasys.tech> References: <20220304174701.1453977-1-marco.solieri@minervasys.tech> MIME-Version: 1.0 From: Luca Miccio In order to efficiently coloring Xen, we need to relocate it and move the xen code to a unique memory region that will be marked as colored for Xen itself. This region will be out target region and it will be placed as high as possibile in RAM. To do that we need to use the old get_xen_paddr function that was part of the relocation feature. Moreover the size of the region we want to relocate is not equal to xen code size anymore because of coloring. In the worst case the target region must be greater than xen code size * avail. colors. However the get_xen_paddr assumes to handle a memory with size equals only to xen code region. Add a new "size" parameter to handle also the coloring case. Signed-off-by: Luca Miccio Signed-off-by: Marco Solieri Acked-by: Stefano Stabellini --- xen/arch/arm/setup.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 0bfe12da57..8d980ce18d 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -570,6 +570,60 @@ static paddr_t __init next_module(paddr_t s, paddr_t *end) return lowest; } +#ifdef CONFIG_COLORING +/** + * get_xen_paddr - get physical address to relocate Xen to + * + * Xen is relocated to as near to the top of RAM as possible and + * aligned to a XEN_PADDR_ALIGN boundary. + */ +static paddr_t __init get_xen_paddr(uint32_t xen_size) +{ + struct meminfo *mi = &bootinfo.mem; + paddr_t min_size; + paddr_t paddr = 0; + int i; + + min_size = (xen_size + (XEN_PADDR_ALIGN-1)) & ~(XEN_PADDR_ALIGN-1); + + /* Find the highest bank with enough space. */ + for ( i = 0; i < mi->nr_banks; i++ ) + { + const struct membank *bank = &mi->bank[i]; + paddr_t s, e; + + if ( bank->size >= min_size ) + { + e = consider_modules(bank->start, bank->start + bank->size, + min_size, XEN_PADDR_ALIGN, 0); + if ( !e ) + continue; + +#ifdef CONFIG_ARM_32 + /* Xen must be under 4GB */ + if ( e > 0x100000000ULL ) + e = 0x100000000ULL; + if ( e < bank->start ) + continue; +#endif + + s = e - min_size; + + if ( s > paddr ) + paddr = s; + } + } + + if ( !paddr ) + panic("Not enough memory to relocate Xen\n"); + + printk("Placing Xen at 0x%"PRIpaddr"-0x%"PRIpaddr"\n", + paddr, paddr + min_size); + + return paddr; +} +#endif + static void __init init_pdx(void) { paddr_t bank_start, bank_size, bank_end;