From nobody Mon Mar 10 02:33:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1741167284; cv=none; d=zohomail.com; s=zohoarc; b=Q9e0sHzs1fxfBNwLfKr7iQbAFw+BEuATvQvd2n2N5hYcyTnwYFcFVZ7QIdlZRRByUcw6kERSC+zkDX+AhSQiVbrk8+vh3ANkVf5uM+e74rDCrIYLcufAHGQMlkNj7Xy4fidDwKdBMbnmcVM3f9Lv2l/qtnZp9fqKnvRyWkXUUD4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741167284; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=l2TmN1BzAMOulOXirn8ZPb+RBDTzjlvF9BdHXNBPEhs=; b=AUZNKQ1bD+zkbDr7bOHCwV2eCIIV+gMVrK/OYlX9GqWFyor23kf1m2YZF4erYfpY4PbOAQZG5v/i/8HBb8rXCct/92J42Qo7G4z/qPWlRPh9XCZ7ndrRWgxm/v23qPjNnqf8CJGBvQdwq9OBEwIaA28SA9PlxmxHHirKoEWKC1g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1741167284490671.8476252645066; Wed, 5 Mar 2025 01:34:44 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.902065.1310018 (Exim 4.92) (envelope-from ) id 1tpl9A-0005rR-1R; Wed, 05 Mar 2025 09:34:36 +0000 Received: by outflank-mailman (output) from mailman id 902065.1310018; Wed, 05 Mar 2025 09:34:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tpl99-0005rE-Sp; Wed, 05 Mar 2025 09:34:35 +0000 Received: by outflank-mailman (input) for mailman id 902065; Wed, 05 Mar 2025 09:34:35 +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 1tpknY-0006ew-AT for xen-devel@lists.xenproject.org; Wed, 05 Mar 2025 09:12:16 +0000 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [2a00:1450:4864:20::135]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ed12a1a3-f9a1-11ef-9898-31a8f345e629; Wed, 05 Mar 2025 10:12:13 +0100 (CET) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-5495078cd59so5447662e87.1 for ; Wed, 05 Mar 2025 01:12:13 -0800 (PST) Received: from EPUAKYIW02F7.. ([95.67.15.120]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5495de028fasm1078264e87.139.2025.03.05.01.12.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Mar 2025 01:12:11 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: ed12a1a3-f9a1-11ef-9898-31a8f345e629 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741165933; x=1741770733; 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=l2TmN1BzAMOulOXirn8ZPb+RBDTzjlvF9BdHXNBPEhs=; b=Bw0Bbwab6Nn7l8N5/AbxGThhI/5BSttUFcUvamw6o4PnBw372zJl5q/Ftm8hJn+YkI qlNATeOw1iPmJUr0WSW6pf/7qmErGR6biBe/Hfi4pEdpPYiEf5CnANzqnplqlreu0J0x i+TnqxPIBM1q0wjSz4jVJ7tr8u5YmNeAXyqhlmkmkLArI2P5Oy0hPlhvNx5pw0bQIxtd jqNUSSsCTNzNSuaigon3wasGvoxnFaZISzvu+Z9sxD5e2G45JdYKhVzI4iXkMR413VLC sP7gBkAm0sDgE6JJgPALS/V41yzs8wSIcKC5pAJX+FpubSi8wtnLOBk6frgF/GJyrqYZ NIew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741165933; x=1741770733; 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=l2TmN1BzAMOulOXirn8ZPb+RBDTzjlvF9BdHXNBPEhs=; b=pM9lRNWYwiTjUEvQRMwcNeH+4KEsAFLLn8LfXp/rfPBRHZF+LYxaPwFGhooEbTWrnX tZf491sDelIDyVmyTZdeak5s+yihECIp1Ev1kb836Y5vMuIcUEsYBW82aLWgwil0kjFN Os41wtvafxQLKne9G43w5wO2NVSzmgPDvRNnDKawDkerbr9pykmOEKx1DC3gbpDzYE8Z rajgXddkER8N5pFz3hWaEyB2mF+f69VDcghf4ry8mKHc/okWOJuYfdat/Hm+b9fTXMiY WQiAsXRwO2FINIQjYglX+k8gQ4iQDsyD9Zo9xNVnneBRo2cySz9BWSukiBfAI0NTl2CA 2f8w== X-Gm-Message-State: AOJu0Yz33CXb2SDeUbcgN6Zw5n8zI0qlNyLyhog9ihw1SNsoc3ZjDN6l Ht1MBj8ODoBkaB7sXk8SA+0A60TOOFemussuOXLgUWGG6PQm+V/6E7BAJTFR X-Gm-Gg: ASbGncseUd71bNplJrfQnHYaVvrVh9PXYZyCeDDn5sZGIV5lvU3ltsa+chaW+cWSuJy cElU55U11K2/EWAVFbLtY641IM+WM7Jz/DVGU5R8r25/10ziocS3doffNC1zPazyX8ngspI3JQ0 hBH76d88mH4sPgtAOjBu+qlmNvSmmCKSzUpmmL95t0kxMqRQ1c89INOXd3/bjED5N9cnxGLSs+i +r3usU1YF/bSpWBIb+xNtmQ6S6V76/fmbJ6FSIO22FxwkRnHW3fZbFL402voW+TLzRnO+dwfTCu H3SoJbTA6VVpA9Qg1TkpiLqeICTr0mH/NREJXRBQ9TgrIlGAMQ== X-Google-Smtp-Source: AGHT+IEawaJ5thoARcmiuSdGY6fIkdNnAu5jE7n/R2L8GjsZ4boHnU4722Pq87bdX6owRtzPi9cjgA== X-Received: by 2002:a05:6512:3d90:b0:545:576:cbca with SMTP id 2adb3069b0e04-5497d3305b7mr807982e87.8.1741165932532; Wed, 05 Mar 2025 01:12:12 -0800 (PST) From: Mykola Kvach To: xen-devel@lists.xenproject.org Cc: Mirela Simonovic , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Saeed Nowshadi , Mykyta Poturai , Mykola Kvach Subject: [PATCH 14/16] xen/arm: Resume memory management on Xen resume Date: Wed, 5 Mar 2025 11:11:22 +0200 Message-ID: <2ef15cb605f987eb087c5496d123c47c01cc0ae7.1741164138.git.xakep.amatop@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1741167286644019100 Content-Type: text/plain; charset="utf-8" From: Mirela Simonovic The MMU needs to be enabled in the resume flow before the context can be restored (we need to be able to access the context data by virtual address in order to restore it). The configuration of system registers prior to branching to the routine that sets up the page tables is copied from xen/arch/arm/arm64/head.S. After the MMU is enabled, the content of TTBR0_EL2 is changed to point to init_ttbr (page tables used at runtime). At boot the init_ttbr variable is updated when a secondary CPU is hotplugged. In the scenario where there is only one physical CPU in the system, the init_ttbr would not be initialized for the use in resume flow. To get the variable initialized in all scenarios in this patch we add that the boot CPU updates init_ttbr after it sets the page tables for runtime. Signed-off-by: Mirela Simonovic Signed-off-by: Saeed Nowshadi Signed-off-by: Mykyta Poturai Signed-off-by: Mykola Kvach --- Changes in V3: - updated commit message - instead of using create_page_tables, enable_mmu, and mmu_init_secondary_c= pu, the existing function enable_secondary_cpu_mm is now used - prepare_secondary_mm (previously init_secondary_pagetables in the previous patch series) is now called at the end of start_xen instead of setup_pagetables. Calling it in the previous location caused a crash - add early printk init during resume Changes in V2: - moved hyp_resume to head.S to place it near the rest of the start code - simplified the code in hyp_resume by using existing functions such as check_cpu_mode, cpu_init, create_page_tables, and enable_mmu --- xen/arch/arm/arm64/head.S | 23 +++++++++++++++++++++++ xen/arch/arm/setup.c | 8 ++++++++ 2 files changed, 31 insertions(+) diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S index 3522c497c5..fab2812e54 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -564,6 +564,29 @@ END(efi_xen_start) #ifdef CONFIG_SYSTEM_SUSPEND =20 FUNC(hyp_resume) + msr DAIFSet, 0xf /* Disable all interrupts */ + + tlbi alle2 + dsb sy /* Ensure completion of TLB flush */ + isb + + ldr x0, =3Dstart + adr x19, start /* x19 :=3D paddr (start) */ + sub x20, x19, x0 /* x20 :=3D phys-offset */ + + /* Initialize the UART if earlyprintk has been enabled. */ +#ifdef CONFIG_EARLY_PRINTK + bl init_uart +#endif + PRINT_ID("- Xen resuming -\r\n") + + bl check_cpu_mode + bl cpu_init + + ldr lr, =3Dmmu_resumed + b enable_secondary_cpu_mm + +mmu_resumed: b . END(hyp_resume) =20 diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index ffcae900d7..3a89ac436b 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -508,6 +508,14 @@ void asmlinkage __init start_xen(unsigned long fdt_pad= dr) for_each_domain( d ) domain_unpause_by_systemcontroller(d); =20 +#ifdef CONFIG_SYSTEM_SUSPEND + /* + * It is called to initialize init_ttbr. + * Without this call, Xen gets stuck after resuming. + */ + prepare_secondary_mm(0); +#endif + /* Switch on to the dynamically allocated stack for the idle vcpu * since the static one we're running on is about to be freed. */ memcpy(idle_vcpu[0]->arch.cpu_info, get_cpu_info(), --=20 2.43.0