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 66AF0C5AD4C for ; Mon, 20 Nov 2023 07:16:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.636438.991935 (Exim 4.92) (envelope-from ) id 1r4yVj-0007HY-8r; Mon, 20 Nov 2023 07:15:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 636438.991935; Mon, 20 Nov 2023 07:15: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 1r4yVj-0007HR-45; Mon, 20 Nov 2023 07:15:59 +0000 Received: by outflank-mailman (input) for mailman id 636438; Mon, 20 Nov 2023 07:15:57 +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 1r4yVh-0007Fv-Na for xen-devel@lists.xenproject.org; Mon, 20 Nov 2023 07:15:57 +0000 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on20604.outbound.protection.outlook.com [2a01:111:f400:7eb2::604]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a49b930d-8774-11ee-9b0e-b553b5be7939; Mon, 20 Nov 2023 08:15:55 +0100 (CET) Received: from SN4PR0501CA0059.namprd05.prod.outlook.com (2603:10b6:803:41::36) by CY5PR12MB6429.namprd12.prod.outlook.com (2603:10b6:930:3b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.27; Mon, 20 Nov 2023 07:15:51 +0000 Received: from SN1PEPF0002BA4F.namprd03.prod.outlook.com (2603:10b6:803:41:cafe::5c) by SN4PR0501CA0059.outlook.office365.com (2603:10b6:803:41::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.16 via Frontend Transport; Mon, 20 Nov 2023 07:15:51 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by SN1PEPF0002BA4F.mail.protection.outlook.com (10.167.242.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7025.12 via Frontend Transport; Mon, 20 Nov 2023 07:15:51 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Mon, 20 Nov 2023 01:15:50 -0600 Received: from [10.252.147.188] (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.34 via Frontend Transport; Mon, 20 Nov 2023 01:15:48 -0600 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: a49b930d-8774-11ee-9b0e-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gFoVutBphW+PFnsrNd2r1bEhz7E2CIK7kmjNbFjT48k1zIAsM8tC/Jd1EJWTgk/QyCbqxp4ZEFFEWChaBRdKwAk1x4i564pX2GnI2m/GExwokN5+xnuKmRyR+ECbVGyePmRDrJQ6n0aCSRj4YMQX8GHzFHfm/dVk7Zj1cTiZCwxnmVaqMKKF1GfJM+xUWZ6DLyDZ0rY0gzYmXgxrjx5WOseUKuRSZRblSf946zzEf5fE3nb4GR/xpRBDI/fsLLp4tUycyloW5nQyxsa3NJlAlHTs9fZRy8/OoyeoBNp5JAHVuxLXxX24MYFl1mEzyfoDwOp6Xuar8qnERvi5dxZBtA== 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=vrlQYgJHgK6HAxzYUY6qjs2fOwtmA1j64QxnoohF3/A=; b=InatV80tqZYqmzrOAGGiw3FAq/ciT4bDQPch08YJYtcXZObO4FvELsx2JMomeNmxk2yOprBwh08Cy8WpiEyaQIa8IC8Gt2Q0gGqb2qwKYT0iQ671kxtSdGdKw3VaWDOoCV9E963gLXyS6bkZTEcmN3OKjwDO/NrVwTsCs8a6emlCGWv17U5XIhr0/Oty1FRFa9CSGf241SoTAjEoT+EKkaS2kfl6lpxsBnKzjbx4fIsbZLVeEWpS7Bb8HQWiT8o3CL3vhzdwbCIDpkncfESngEML9B6+i8La8bQF1NPMLk+sBsl+K3vYeJNya8LT+u2OyGyOVUQb3sYMV4H4tMDUpQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) 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=vrlQYgJHgK6HAxzYUY6qjs2fOwtmA1j64QxnoohF3/A=; b=baumge+7UV8Y16nIUDBz1b/bo+ri5AlFvU6UddFhkgJGyAkbh39y3CUppRoXhD6b846xF1fXv75stIQ1TpnwJ4PpBTCX/2XCGkYbI0KQGecymhTFwfigGCoYQZkgSPkYFcOAQDrPBuWtgvPUkielktEC7CY1SIxGNXXzlR74eLY= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Message-ID: <8a1aba2d-a940-44ab-8dea-99f44e74eead@amd.com> Date: Mon, 20 Nov 2023 08:15:43 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [XEN v4 2/2] xen/arm32: head Split and move MMU-specific head.S to mmu/head.S Content-Language: en-US To: Ayan Kumar Halder , CC: , , , , , , References: <20231117153101.2902792-1-ayan.kumar.halder@amd.com> <20231117153101.2902792-3-ayan.kumar.halder@amd.com> From: Michal Orzel In-Reply-To: <20231117153101.2902792-3-ayan.kumar.halder@amd.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4F:EE_|CY5PR12MB6429:EE_ X-MS-Office365-Filtering-Correlation-Id: 8a1e9baa-d450-4891-1422-08dbe99886f5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1MU1AxmXVndGbdGJoq9ZCDqtXk3wj3qQhxx1zjxpAORid6JrPr767fm3yGWBBVWzy/a9iRmv4ZKAsMxs4T9VCCjMOra87mqGmE7/ClisIXhP2EE9ARQgEB/mO0qbVyVyXDSS8ZhRv1exIe7rgZL3cH0Bnuw491l7pilnEQ3jZ2hq1eykvk70VYFNGS8E3yyitlLVsYNbxh1ITgUSz9XzLWjWVDX+xKH4bVqWB96cmuhrK7hOEZRUHX6lNufi+XqZstEHu4hVEtDAT/K4TJwimX3hs+oixzSbPBvtMEyPsF1usRyzPnaCQE1zdApe5gS5NjWhZjFtFarWE7ZurwQ311dyo/rWSakdUY3LfQnMCSoLTS4TVpF232fW9y05H9f6zwBjusj5xEpe2OSmhQuEhV2PBlNXw5PH5UwFD5UVwybFvJdD9Gnqi7MdAw4+N3eWK7Zk8GqxUTPHGXLBSu5D50yGSI/2bBdf4T4qNFM94OKPsdZdaWoaMfDHpRcOCnpaZOrid7k/qJGAblLewIHZXMmdICoDiomstc0RelDJDrp4EcT5TUug8j7K25YN97mVGalVVTLPZwQG4I5e81V2w0dktbZnFIA6qmpvy0sUDPcDav7wkyne2vYFDxpW/LRI4wzoqW6zts2yh4X7lM7tI0fAIO6CgTq+ZJAQ1ORQsIDeXOvm1tab//GtglHxjFEAtpQt8lu4C8r8CFS7E8HTrLouHsE0I0tCqmiNIoNlkLOioHmoqkVyS09XgsrCxdYhyHyy23ZO/YqvuPaXTOJx6PjxSGDTf5UWlGZHw8F8Q9jqbEt9m/0OWdQCiqCP3ZlB7BfHuV9kk7mMecch/qgCuziqyfMEqJN+HId548Me+Lg= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(376002)(136003)(396003)(346002)(230922051799003)(230173577357003)(230273577357003)(1800799012)(451199024)(64100799003)(186009)(82310400011)(36840700001)(40470700004)(46966006)(4326008)(44832011)(2906002)(8676002)(31686004)(8936002)(41300700001)(26005)(2616005)(110136005)(70206006)(316002)(16576012)(70586007)(54906003)(53546011)(6666004)(5660300002)(426003)(36860700001)(478600001)(336012)(83380400001)(47076005)(40480700001)(81166007)(356005)(82740400003)(86362001)(31696002)(36756003)(40460700003)(43740500002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2023 07:15:51.0941 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8a1e9baa-d450-4891-1422-08dbe99886f5 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002BA4F.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6429 Hi Ayan, On 17/11/2023 16:31, Ayan Kumar Halder wrote: > The MMU specific code in head.S will not be used on MPU systems. > Instead of introducing more #ifdefs which will bring complexity > to the code, move MMU related code to mmu/head.S and keep common > code in head.S. Two notes while moving: > - As "fail" in original head.S is very simple and this name is too > easy to be conflicted, duplicate it in mmu/head.S instead of > exporting it. > - Realigned ".macro ret" so that the alignment matches to the other > macros. > - Rename puts to asm_puts, putn to asm_putn (this denotes that the > macros are used within the context of assembly only). > - Use ENTRY() for enable_secondary_cpu_mm, enable_boot_cpu_mm, > setup_fixmap, asm_puts, asm_putn as they will be used externally. > > Also move the assembly macros shared by head.S and mmu/head.S to > macros.h. > > This is based on 6734327d76be ("xen/arm64: Split and move MMU-specific head.S to mmu/head.S"). > > Signed-off-by: Ayan Kumar Halder Reviewed-by: Michal Orzel with a few remarks... > --- > > Changes from v1 :- > > 1. Added a commit message > 2. Moved load_paddr to mmu/head.S > > v2 :- > > 1. Renamed puts to asm_puts and putn to asm_putn. Exported asm_putn(). > 2. Moved XEN_TEMPORARY_OFFSET to head.S. > 3. Some style issues. > > v3 :- > > 1. Updated the comments on top of asm_puts() and asm_putn(). > 2. Removed some stubs. > 3. PRINT() invokes asm_puts. > > xen/arch/arm/arm32/head.S | 630 +----------------------- > xen/arch/arm/arm32/mmu/Makefile | 1 + > xen/arch/arm/arm32/mmu/head.S | 573 +++++++++++++++++++++ > xen/arch/arm/include/asm/arm32/macros.h | 58 ++- > 4 files changed, 638 insertions(+), 624 deletions(-) > create mode 100644 xen/arch/arm/arm32/mmu/head.S > [...] > > @@ -947,8 +335,6 @@ RODATA_STR(hex, "0123456789abcdef") > > ENTRY(early_puts) > init_uart: > -puts: > -putn: mov pc, lr You removed putn, puts and even the return. Looking at the codebase, early_puts global makes no sense and init_uart is only used within #ifdef. So I would expect the entire block to be removed. > > #endif /* !CONFIG_EARLY_PRINTK */ > > diff --git a/xen/arch/arm/arm32/mmu/Makefile b/xen/arch/arm/arm32/mmu/Makefile > index b18cec4836..a8a750a3d0 100644 > --- a/xen/arch/arm/arm32/mmu/Makefile > +++ b/xen/arch/arm/arm32/mmu/Makefile > @@ -1 +1,2 @@ > +obj-y += head.o > obj-y += mm.o > diff --git a/xen/arch/arm/arm32/mmu/head.S b/xen/arch/arm/arm32/mmu/head.S > new file mode 100644 > index 0000000000..6d427328f3 > --- /dev/null > +++ b/xen/arch/arm/arm32/mmu/head.S > @@ -0,0 +1,573 @@ > +/* SPDX-License-Identifier: GPL-2.0-or-later */ > +/* > + * xen/arch/arm/arm32/mmu/head.S > + * > + * Arm32 MMU specific start-of-day code. > + */ > + > +#include > +#include > + > +#define PT_PT 0xf7f /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=1 P=1 */ > +#define PT_MEM 0xf7d /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=0 P=1 */ > +#define PT_MEM_L3 0xf7f /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=1 P=1 */ > +#define PT_DEV 0xe71 /* nG=1 AF=1 SH=10 AP=01 NS=1 ATTR=100 T=0 P=1 */ > +#define PT_DEV_L3 0xe73 /* nG=1 AF=1 SH=10 AP=01 NS=1 ATTR=100 T=1 P=1 */ > + > +#define PT_UPPER(x) (PT_##x & 0xf00) > +#define PT_LOWER(x) (PT_##x & 0x0ff) > + > +/* Convenience defines to get slot used by Xen mapping. */ > +#define XEN_FIRST_SLOT first_table_offset(XEN_VIRT_START) > +#define XEN_SECOND_SLOT second_table_offset(XEN_VIRT_START) > + > +/* Offset between the early boot xen mapping and the runtime xen mapping */ > +#define XEN_TEMPORARY_OFFSET (TEMPORARY_XEN_VIRT_START - XEN_VIRT_START) > + > +.macro load_paddr rb, sym > + mov_w \rb, \sym > + add \rb, \rb, r10 > +.endm > + > +/* > + * Flush local TLBs > + * > + * @tmp: Scratch register > + * > + * See asm/arm32/flushtlb.h for the explanation of the sequence. > + */ > +.macro flush_xen_tlb_local tmp > + dsb nshst > + mcr CP32(\tmp, TLBIALLH) > + dsb nsh > + isb > +.endm > + > +/* > + * Enforce Xen page-tables do not contain mapping that are both > + * Writable and eXecutables. > + * > + * This should be called on each secondary CPU. > + */ > +.macro pt_enforce_wxn tmp > + mrc CP32(\tmp, HSCTLR) > + orr \tmp, \tmp, #SCTLR_Axx_ELx_WXN > + dsb > + mcr CP32(\tmp, HSCTLR) > + /* > + * The TLBs may cache SCTLR_EL2.WXN. So ensure it is synchronized > + * before flushing the TLBs. > + */ > + isb > + flush_xen_tlb_local \tmp > +.endm > + > +/* Macro to find the slot number at a given page-table level > + * > + * slot: slot computed > + * virt: virtual address > + * lvl: page-table level > + * > + * Note that ubxf is unpredictable when the end bit is above 32-bit. So we > + * can't use it for first level offset. > + */ > +.macro get_table_slot, slot, virt, lvl > + .if \lvl == 1 > + lsr \slot, \virt, #XEN_PT_LEVEL_SHIFT(\lvl) > + .else > + ubfx \slot, \virt, #XEN_PT_LEVEL_SHIFT(\lvl), #XEN_PT_LPAE_SHIFT > + .endif > +.endm > + > +/* > + * Macro to create a page table entry in \ptbl to \tbl (physical > + * address) > + * > + * ptbl: table symbol where the entry will be created > + * tbl: physical address of the table to point to > + * virt: virtual address > + * lvl: page-table level > + * > + * Preserves \virt > + * Clobbers \tbl, r1 - r3 > + * > + * Note that \tbl and \virt should be in a register other than r1 - r3 > + */ > +.macro create_table_entry_from_paddr, ptbl, tbl, virt, lvl > + get_table_slot r1, \virt, \lvl /* r1 := slot in \tbl */ > + lsl r1, r1, #3 /* r1 := slot offset in \tbl */ > + > + movw r2, #PT_PT /* r2:r3 := right for linear PT */ > + orr r2, r2, \tbl /* + \tbl paddr */ > + mov r3, #0 > + > + adr_l \tbl, \ptbl /* \tbl := (v,p)addr of \ptbl */ > + > + strd r2, r3, [\tbl, r1] > +.endm > + > + NIT: too many blank lines [...] > diff --git a/xen/arch/arm/include/asm/arm32/macros.h b/xen/arch/arm/include/asm/arm32/macros.h > index a4e20aa520..c41861efbe 100644 > --- a/xen/arch/arm/include/asm/arm32/macros.h > +++ b/xen/arch/arm/include/asm/arm32/macros.h > @@ -1,8 +1,62 @@ > #ifndef __ASM_ARM_ARM32_MACROS_H > #define __ASM_ARM_ARM32_MACROS_H > > - .macro ret > +.macro ret > mov pc, lr > - .endm > +.endm > > +/* > + * Move an immediate constant into a 32-bit register using movw/movt > + * instructions. > + */ > +.macro mov_w reg, word > + movw \reg, #:lower16:\word > + movt \reg, #:upper16:\word > +.endm > + > +/* > + * Pseudo-op for PC relative adr , where is > + * within the range +/- 4GB of the PC. > + * > + * @dst: destination register > + * @sym: name of the symbol > + */ > +.macro adr_l, dst, sym > + mov_w \dst, \sym - .Lpc\@ > + .set .Lpc\@, .+ 8 /* PC bias */ > + add \dst, \dst, pc > +.endm > + > +#ifdef CONFIG_EARLY_PRINTK > +/* > + * Macro to print a string to the UART, if there is one. > + * > + * Clobbers r0 - r3 > + */ > +#define PRINT(_s) \ > + mov r3, lr ;\ > + adr_l r0, 98f ;\ > + bl asm_puts ;\ > + mov lr, r3 ;\ > + RODATA_STR(98, _s) > + > +/* > + * Macro to print the value of register \rb > + * > + * Clobbers r0 - r4 > + */ > +.macro print_reg rb > + mov r0, \rb > + mov r4, lr > + bl asm_putn > + mov lr, r4 > +.endm > + > +#else /* CONFIG_EARLY_PRINTK */ > +#define PRINT(s) > + > +.macro print_reg rb > +.endm > + > +#endif /* !CONFIG_EARLY_PRINTK */ please add one blank line here to separate #endif's > #endif /* __ASM_ARM_ARM32_MACROS_H */ ~Michal