From patchwork Sun Jun 25 20:49:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 13292193 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 67ACAC001B3 for ; Sun, 25 Jun 2023 20:49:46 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.554874.866314 (Exim 4.92) (envelope-from ) id 1qDWfh-0003LN-3b; Sun, 25 Jun 2023 20:49:21 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 554874.866314; Sun, 25 Jun 2023 20:49:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qDWfh-0003LF-0C; Sun, 25 Jun 2023 20:49:21 +0000 Received: by outflank-mailman (input) for mailman id 554874; Sun, 25 Jun 2023 20:49:19 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qDWff-00035f-Fe for xen-devel@lists.xenproject.org; Sun, 25 Jun 2023 20:49:19 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qDWff-0003MI-7s; Sun, 25 Jun 2023 20:49:19 +0000 Received: from 54-240-197-232.amazon.com ([54.240.197.232] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1qDWff-00021M-0M; Sun, 25 Jun 2023 20:49:19 +0000 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" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=ZbAv0laYLu6yT3k2hkA4Gj70LOYt07z08AMTeISDAIs=; b=gBjp3U5esOIGtiVaIIWDIkasBy svhJkygMb8nct3CANun88vUSVtpOSUgtxsaM6oW3LjZYYHAPIee8zHCW8ho+240q28aZEQzi44pwg pxebZGE+aTsoDlUD6yB08cL3CV5xjnmRtJ/oAiFvf7zce6iRzGrBzhB/U/Y9AbW+SdJw=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: Luca.Fancellu@arm.com, michal.orzel@amd.com, Henry.Wang@arm.com, Julien Grall , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH 3/9] xen/arm32: head: Don't map too much in boot_third Date: Sun, 25 Jun 2023 21:49:01 +0100 Message-Id: <20230625204907.57291-4-julien@xen.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230625204907.57291-1-julien@xen.org> References: <20230625204907.57291-1-julien@xen.org> MIME-Version: 1.0 From: Julien Grall At the moment, we are mapping the size of the reserved area for Xen (i.e. 2MB) even if the binary is smaller. We don't exactly know what's after Xen, so it is not a good idea to map more than necessary for a couple of reasons: * We would need to use break-before-make if the extra PTE needs to be updated to point to another region * The extra area mapped may be mapped again by Xen with different memory attribute. This would result to attribue mismatch. Therefore, rework the logic in create_page_tables() to map only what's necessary. To simplify the logic, we also want to make sure _end is page-aligned. So align the symbol in the linker and add an assert to catch any change. Signed-off-by: Julien Grall Reviewed-by: Michal Orzel --- xen/arch/arm/arm32/head.S | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index f9f7be9588b1..997c8a4fbbc1 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -462,6 +462,19 @@ create_page_tables: create_table_entry boot_pgtable, boot_second, r0, 1 create_table_entry boot_second, boot_third, r0, 2 + /* + * Find the size of Xen in pages and multiply by the size of a + * PTE. This will then be compared in the mapping loop below. + * + * Note the multiplication is just to avoid using an extra + * register/instruction per iteration. + */ + mov_w r0, _start /* r0 := vaddr(_start) */ + mov_w r1, _end /* r1 := vaddr(_end) */ + sub r0, r1, r0 /* r0 := effective size of Xen */ + lsr r0, r0, #PAGE_SHIFT /* r0 := Number of pages for Xen */ + lsl r0, r0, #3 /* r0 := Number of pages * PTE size */ + /* Setup boot_third: */ adr_l r4, boot_third @@ -476,7 +489,7 @@ create_page_tables: 1: strd r2, r3, [r4, r1] /* Map vaddr(start) */ add r2, r2, #PAGE_SIZE /* Next page */ add r1, r1, #8 /* Next slot */ - cmp r1, #(XEN_PT_LPAE_ENTRIES<<3) /* 512*8-byte entries per page */ + cmp r1, r0 /* Loop until we map all of Xen */ blo 1b /*