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 9AE2CC04E69 for ; Mon, 7 Aug 2023 11:24:13 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.578174.905570 (Exim 4.92) (envelope-from ) id 1qSyLE-0007gZ-9S; Mon, 07 Aug 2023 11:24:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 578174.905570; Mon, 07 Aug 2023 11:24:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qSyLE-0007gS-6r; Mon, 07 Aug 2023 11:24:04 +0000 Received: by outflank-mailman (input) for mailman id 578174; Mon, 07 Aug 2023 11:24:03 +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 1qSyLD-0007gM-Kl for xen-devel@lists.xenproject.org; Mon, 07 Aug 2023 11:24:03 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2060e.outbound.protection.outlook.com [2a01:111:f400:7e8a::60e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e6bacaad-3514-11ee-8613-37d641c3527e; Mon, 07 Aug 2023 13:24:01 +0200 (CEST) Received: from SN6PR12MB2621.namprd12.prod.outlook.com (2603:10b6:805:73::15) by DM6PR12MB4862.namprd12.prod.outlook.com (2603:10b6:5:1b7::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.26; Mon, 7 Aug 2023 11:23:55 +0000 Received: from SN6PR12MB2621.namprd12.prod.outlook.com ([fe80::4541:2a3d:737d:b194]) by SN6PR12MB2621.namprd12.prod.outlook.com ([fe80::4541:2a3d:737d:b194%5]) with mapi id 15.20.6652.025; Mon, 7 Aug 2023 11:23:55 +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" X-Inumbo-ID: e6bacaad-3514-11ee-8613-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vyn+ugfKva6Ol2VbfD7KopPEChSkzbj0vCUv2sS6sNmi2UJaOqjvvXEaGWxnz3RT1T1Cr02fQLmv6iqreZ1JBaM5O5LZQTwLBnng0e64dmLCStVBsxZHw6y6epA32XLAeHMihj4xnEWAGYDY+GwXjZCJ9VN3g17HDDnXfX9hkOdpTwlGo44i6ghO+WPNrPMjR236xkcQPDpZ2VNnN4S6BPG8KnI4gtDnj3CGrn+Ftw5hZ/NO+8Jst/dJ2oyZEq6O20antqcChtdjaEeMJlM0AMElvnlAS793FDoGksIyPeEI8dyYf0YVbgYN398fW1f0TbVKLohbkZI+dwQ0OAmdpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=bvOt5/tl3yC/oNNRETEh24zwDsRxp4LDd3mEtXQlZgI=; b=T5sRqE/8wwOBTM9+rya6YsJf3OnaLz4EJ4KDApL0xI7mTkgAjRJqZhuJvDS2nnJCYH8N87VOtRCQ489HIW2bIzfO5L3rz16vwj5Ki0z4z/+/BWYy/iigf0zUSUr6SPzUXoeU4Nt5A4q39T7f2sAHYY8eorxzifJ+QYMgNTqsg8vEIIrKnfj7XPc5com3wzUaLh3F3Xi9jNxIE+HKep8Cx/CTvHPY32aEygfJmSoYK+Y38d4boH2lzSWg49hFUucTOXtDjq3+qUBWrzvMiW4eHjXrsIpll8tuZj/ZGGyWSSUB39tRyJHkmgQ38YfRxMoehOIA2nRZK+M8doeZlmtOwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bvOt5/tl3yC/oNNRETEh24zwDsRxp4LDd3mEtXQlZgI=; b=FqIDyHo1zlqMCUmyai1kw+R449lSfbEgps1Ndc2hu4uOPSBhRvhbJQH5X3Fnji5K9vwmgZfezt3nxJP1EmQ0SWzbOscHnBT+MIDC15BGzYha0A0I4CATB50UiDy4xVw++3sFCJN44hXY1UqJagIW/IRqi6O3bZj53Oqwbg0Uom0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Message-ID: <79de42d1-35db-79b1-da2a-f08a72fa53d7@amd.com> Date: Mon, 7 Aug 2023 12:23:47 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v4 01/13] xen/arm64: head.S: Introduce enable_{boot,secondary}_cpu_mm To: Henry Wang , xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Penny Zheng References: <20230801034419.2047541-1-Henry.Wang@arm.com> <20230801034419.2047541-2-Henry.Wang@arm.com> From: Ayan Kumar Halder In-Reply-To: <20230801034419.2047541-2-Henry.Wang@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO2P265CA0472.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a2::28) To SN6PR12MB2621.namprd12.prod.outlook.com (2603:10b6:805:73::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN6PR12MB2621:EE_|DM6PR12MB4862:EE_ X-MS-Office365-Filtering-Correlation-Id: 8766813a-b5f0-49db-76bb-08db9738c903 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VForp5SiL38FF1PvA5dObd9eCYgABmA/tjJqUKoRjpt06Ue3Rw630lOTGSF3BiO2vd4mHwhJUF3p1CH61hq5FCqqlRP3loNt6Y0QW9seJ4hcM3bUKwELVt+xMwkQKz/Vjr6IG2+XpwErhlE6kIcX/CN4n6dc/APMpAs0OyWufYUhS/OFU0bUJ2eYOwALQi3X8HrhrktsNHNsXsEVFZB9QupofkY1e0rGqPRmeQ33rvmJHE06a8Gy0KqINlXdKCmEH39TkzQbbRl9M1bzzgbwlq1KS6wksX2RXpvWyluSHShijXlukPgft7vy6aPnjtuhzgWWm+ZE4G0wWWyBjQXJngX4cE2kHUerbT2Z/jm39tZb4Zo0ZDHCtjne/qHh/SyO+WH9AocY0fcix1T84xpESvF6xB+x51gT78SNowdEcduYWMK8aU2SCNTh2Dcu5Kr+jZe4aLx17H5IPhb5kWvoUvZpuBqF8SlBDwShswj8d8wvIqByNYc+bjfA6Jwzo7WowU4atjThw2g/UPVMx1FWoT1nYVmabQNPl8Du2/zuZoUmcHF7yODPUtil0UNCrMk1f2ug6pnqhkoanBS0NYq0h3+O3sdPwJxCCIKBA0XhtZbz4y/WLrAJ83emOHc8bbjfcuw7dwOfmIX13cFFTDQURg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2621.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(396003)(136003)(346002)(376002)(366004)(451199021)(186006)(1800799003)(2616005)(36756003)(6512007)(4326008)(316002)(478600001)(54906003)(38100700002)(6666004)(66946007)(6486002)(66556008)(66476007)(31696002)(53546011)(6506007)(41300700001)(26005)(8676002)(8936002)(2906002)(83380400001)(5660300002)(31686004)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?SmtzaVFaTWpSZGZzS2hvTVByRndtS1R0ekJ6NjE4WCtTOWJZdmJ5WHlHN1F1?= =?utf-8?B?VFloYkhmcDFwRkc2YXZ2UGw1ZXRBVjVEZXVLMTZEK1Y2Z0RpRFJrSGt0eHRN?= =?utf-8?B?bk1wMWFINlhjZXBJR2lrL2ZZQmhFeUk1M1g3cCtKbngzSlN2KzdTYS9zZGpU?= =?utf-8?B?U3pWeW5ibXZuSTJkT2lrV1NnUEw3WmFhNnV5ZFFWQ0FhMnJoYVMyQS90bEdQ?= =?utf-8?B?WW1SaEkwOEhOWWlTLy96N2swQ3l2YUlvSFJSM2U4VXRlTmRNb0hQTlJiZnhw?= =?utf-8?B?WERKdkZMQVFpanA2VitiK2lDYWJzd2tnRHN0QjZoNmRyUDdUN0xzcG5aUFFk?= =?utf-8?B?TGI3Uzc2R2ZlaWd5N3VFL1pub09uM1FIWWJRc3BQRWZNZHRWMWYzTXRaTmJX?= =?utf-8?B?WjZYR1JGRXlaTVkzTDRJLzNkSEl3NXBHS2p2ZmlDMUF4REtrdGFXcXh1OWFP?= =?utf-8?B?YWl3ZzlWZkNNVkxaMnU3ZFBHeVUvMjcyeTJscGwwU25oMm1mc0gwaUpWR1FC?= =?utf-8?B?SFBLMGk0V01DSFhlRTZ6dXk4ZkV3aGFiUnR2WWJKM24yNzNHM2J4UTFtenR0?= =?utf-8?B?RlhVU28vQU5SRWFPWlFPVTdjOXRjZ0IzUXQzZE55NnkzelNtTWVpZVRqZm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zZVVllINENqRXlEUWMzWWw5?= =?utf-8?B?cDJJSWxKaHJnU1VJR1BSWWFRYlgzdXRSVHRuOEdUaGJUcHp6NzN0K0t1VUlH?= =?utf-8?B?Sm5BVmNCM3FHb0tBL0pIUEtBN0hiQk5LZDUwTDBSVGR6WS83S1A2SEVLaWZD?= =?utf-8?B?OWVPeWpLclorL2Z2Wm1BZFVJbWdTWStHbUdBOUJRVnk4K2taUTlHYWhBRWRt?= =?utf-8?B?YXNSWGZTZTdNbDgwMDNMOVBEQlpjYzQwNWhCTWJ2YXdEVUNqbFI0VkY3UlhK?= =?utf-8?B?NE5VWExPY2dmVWZtQkFTcVAvNUJqRW1FK0NaUDZ0MVlRSXhqVHdIRDBoaE95?= =?utf-8?B?V1ZBem5Qd1MwZ3BXajBWWDdJTVlLbUgyeGtEcmIxTTk0b3pTa0dNU0NFK1BM?= =?utf-8?B?eUQxQklhVHhJNGVVWTkyZHlOUC9ReURqYmIzVnJxQUNRY3hxMXFtOVdjN3lD?= =?utf-8?B?UEg1c2NybVRsWTVaS3BYeTV1cUZNdExZaXUrR2dZSG51MWZQSVJyRHJsVkRT?= =?utf-8?B?ZDZtcGtaUktabmYxcXRCZ1B4bHVjRWZZVGRUOXd4YzR4YlBvbWxwb0FJYjRt?= =?utf-8?Q?paj2/jwK+uMs41JFqGv4qInQo?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8766813a-b5f0-49db-76bb-08db9738c903 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2621.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2023 11:23:55.2558 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: K7R5tIoPRb+IRwelSVHurPqHXbn4Z8haDCfRSUr3BfhJ7/B7idSGbsh1W/vhZkgaP04fU1SL4VNARmHw0CnpoQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4862 Hi Henry, On 01/08/2023 04:44, Henry Wang wrote: > CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email. > > > From: Wei Chen > > At the moment, on MMU system, enable_mmu() will return to an > address in the 1:1 mapping, then each path is responsible to > switch to virtual runtime mapping. Then remove_identity_mapping() > is called on the boot CPU to remove all 1:1 mapping. > > Since remove_identity_mapping() is not necessary on Non-MMU system, > and we also avoid creating empty function for Non-MMU system, trying > to keep only one codeflow in arm64/head.S, we move path switch and > remove_identity_mapping() in enable_mmu() on MMU system. > > As the remove_identity_mapping should only be called for the boot > CPU only, so we introduce enable_boot_cpu_mm() for boot CPU and > enable_secondary_cpu_mm() for secondary CPUs in this patch. > > Signed-off-by: Wei Chen > Signed-off-by: Penny Zheng > Signed-off-by: Henry Wang With two comments Reviewed-by: Ayan Kumar Halder Tested-by: Ayan Kumar Halder > --- > v4: > - Clarify remove_identity_mapping() is called on boot CPU and keep > the function/proc format consistent in commit msg. > - Drop inaccurate (due to the refactor) in-code comment. > - Rename enable_{boot,runtime}_mmu to enable_{boot,secondary}_cpu_mm. > - Reword the in-code comment on top of enable_{boot,secondary}_cpu_mm. > - Call "fail" for unreachable code. > v3: > - new patch > --- > xen/arch/arm/arm64/head.S | 89 ++++++++++++++++++++++++++++++--------- > 1 file changed, 70 insertions(+), 19 deletions(-) > > diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S > index 31cdb54d74..2af9f974d5 100644 > --- a/xen/arch/arm/arm64/head.S > +++ b/xen/arch/arm/arm64/head.S > @@ -313,21 +313,11 @@ real_start_efi: > > bl check_cpu_mode > bl cpu_init > - bl create_page_tables > - load_paddr x0, boot_pgtable > - bl enable_mmu > > - /* We are still in the 1:1 mapping. Jump to the runtime Virtual Address. */ > - ldr x0, =primary_switched > - br x0 > + ldr lr, =primary_switched > + b enable_boot_cpu_mm > + > primary_switched: > - /* > - * The 1:1 map may clash with other parts of the Xen virtual memory > - * layout. As it is not used anymore, remove it completely to > - * avoid having to worry about replacing existing mapping > - * afterwards. > - */ > - bl remove_identity_mapping > bl setup_fixmap > #ifdef CONFIG_EARLY_PRINTK > /* Use a virtual address to access the UART. */ > @@ -372,13 +362,10 @@ GLOBAL(init_secondary) > #endif > bl check_cpu_mode > bl cpu_init > - load_paddr x0, init_ttbr > - ldr x0, [x0] > - bl enable_mmu > > - /* We are still in the 1:1 mapping. Jump to the runtime Virtual Address. */ > - ldr x0, =secondary_switched > - br x0 > + ldr lr, =secondary_switched > + b enable_secondary_cpu_mm > + > secondary_switched: > #ifdef CONFIG_EARLY_PRINTK > /* Use a virtual address to access the UART. */ > @@ -737,6 +724,70 @@ enable_mmu: > ret > ENDPROC(enable_mmu) > > +/* > + * Enable mm (turn on the data cache and the MMU) for secondary CPUs. > + * The function will return to the virtual address provided in LR (e.g. the > + * runtime mapping). > + * > + * Inputs: > + * lr : Virtual address to return to. > + * > + * Clobbers x0 - x5 > + */ > +enable_secondary_cpu_mm: I will prefer "enable_secondary_cpu_mmu" as it is MMU specific. And ... > + mov x5, lr > + > + load_paddr x0, init_ttbr > + ldr x0, [x0] > + > + bl enable_mmu > + mov lr, x5 > + > + /* return to secondary_switched */ > + ret > +ENDPROC(enable_secondary_cpu_mm) > + > +/* > + * Enable mm (turn on the data cache and the MMU) for the boot CPU. > + * The function will return to the virtual address provided in LR (e.g. the > + * runtime mapping). > + * > + * Inputs: > + * lr : Virtual address to return to. > + * > + * Clobbers x0 - x5 > + */ > +enable_boot_cpu_mm: prefer "enable_boot_cpu_mmu" as it is MMU specific as well. - Ayan > + mov x5, lr > + > + bl create_page_tables > + load_paddr x0, boot_pgtable > + > + bl enable_mmu > + mov lr, x5 > + > + /* > + * The MMU is turned on and we are in the 1:1 mapping. Switch > + * to the runtime mapping. > + */ > + ldr x0, =1f > + br x0 > +1: > + /* > + * The 1:1 map may clash with other parts of the Xen virtual memory > + * layout. As it is not used anymore, remove it completely to > + * avoid having to worry about replacing existing mapping > + * afterwards. Function will return to primary_switched. > + */ > + b remove_identity_mapping > + > + /* > + * Below is supposed to be unreachable code, as "ret" in > + * remove_identity_mapping will use the return address in LR in advance. > + */ > + b fail > +ENDPROC(enable_boot_cpu_mm) > + > /* > * Remove the 1:1 map from the page-tables. It is not easy to keep track > * where the 1:1 map was mapped, so we will look for the top-level entry > -- > 2.25.1 > >