Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp65712ybh; Tue, 17 Mar 2020 18:14:29 -0700 (PDT) X-Google-Smtp-Source: ADFU+vt0766JIkVBAXt918yeIVRWzT/AGTUkqS7bJU9NqFQIGo5Tax+ImieM0E0HmfQgBPGq7ad/ X-Received: by 2002:aca:130f:: with SMTP id e15mr1309108oii.160.1584494069634; Tue, 17 Mar 2020 18:14:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584494069; cv=none; d=google.com; s=arc-20160816; b=mpGT8c2V9NNYQqetorTt72PC4ZLm2b1ud6dem2M0VjwBkTM3ULfsTeCU2558jOusCo sSHz7yZsWENWPpbeT7ZOsCrkhwkRjGDj1Zg6X2LS+7lQHA30lDgIik7eNj0r2VyVjnB4 r/hC7BiiXqQM/wQTNIlOliMZY6z9K37ftM3io9Kk0MfRsWJJxib1KjiDfWAAjkxBQDG9 AWKUXM/ShBPsX7rOpHsn3FenEhmzm+HFTObtCxc8L3IWSCXM9quOJSeXovC846OTDfsd Ry2fDuRB83tu+abH3XV4TJRlinQ8FK9+XqvGPUw274qWsOH6bnyWvhI36NB7vT7/RUO+ Zlyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :wdcironportexception:ironport-sdr:ironport-sdr:ironport-sdr :dkim-signature; bh=uy0KskCPp61QyAywLIT1Y9CxhHBz0oR+hBc2LGXTJcw=; b=dz2EqZx8a/qOXl2ZmM97LWLn+gc3MSXGDurQjJIl5SVt5qbrR7sMJCsCjWdWhpdBT6 4R2miiFBtyTuOL7btmbeGw/IjHyljELQMFXdQWD5NH7Llh4bMJ3BnUf4gzo/KLJTT6kh jzU6iFEqqy1E/2fLxqKqKq1iqus148B9rqwBrLutdxYYuJTX1Ot/hgtQ+l4/uSRDVpYF NWqte7H6Iur2QUHTWJobbHObcW4VNi7zXPJB13962sgTiiHYqe39aun/fbfTUZL4hF2G VqUB+QlopP0Nfnc54rG8Mog04r4eyq1Y8bPcGWmoUHnMHKNMRkrIfxv5/uQOpNOQYyaA jPmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=dO2liORo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l63si2626789oif.161.2020.03.17.18.14.17; Tue, 17 Mar 2020 18:14:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=dO2liORo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727384AbgCRBMC (ORCPT + 99 others); Tue, 17 Mar 2020 21:12:02 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:45921 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727361AbgCRBMA (ORCPT ); Tue, 17 Mar 2020 21:12:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1584493920; x=1616029920; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JYTimahxcw8q6zIu6hPSn8yTDPvVgrP3ZU4qSOXZc/o=; b=dO2liORoqSDoxOgzQaOCWRAd+CXGkj/4ibuYOaRqZ6Mcfk5QzcK+IlQe h7R5yBiZYY987m/JCXM9bxtgKb+6y5aIqGJVVlyI2mbb6t7W32EO5cJr0 v/+oz7y17k6BWTw89o59AqWlZjD50VnkYkkHlJjNJaa9IjPy3AgPwuix1 2do/2bXQxDHXwbnLj6zuISy4eRdkwgPtjy0jtaVT5ycVJXmvs0+rWKggD 093rPg+Q/HG5yMxCZAy1BoDr1QjNiy8FyHOLQyZ/QopmDmj8KCxCpccAr UvvMZrIlQBMAmMFzEvwnSPcSGXxanBx2pMh+In6LodkkcguPekKPRZ4rW Q==; IronPort-SDR: 9T5L7LKs2d+HWTR7Da0v93CavxnEoanotpWm8vehscr2Tazn+w99uiQKqul/MT06h+Mk0NWWAV /cv5GmsPUo46UyM1ARzTvq7dSeGnJ6C2Ac8xycex+mkQy3ied+LfChV4M5G5bgLi/57tSsQPP5 pzqdrqOp6KmHDk3ml5YGhvCs5wxH2AusodII0WrP63cnPv8D67qTzvbyFeRC8SIit4gO6mWaw4 hLuZ4ycbMuavswa7GH1sVeUYTueyPB/dmjSfGpNnSChK3VcmKIsRwewXKiYtJtKDAdCgOXUOPq tdA= X-IronPort-AV: E=Sophos;i="5.70,565,1574092800"; d="scan'208";a="133241517" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 18 Mar 2020 09:11:59 +0800 IronPort-SDR: JOhygpudMmoX0LTX5JKbhybyEQNPQeHMW90SlQ9X4mEzrgwDI2N0fXIO6PQ715gzGnjNLONu5H x6AZXuS6v9AfGi+X6PaBakwvnWs5wrlpDA9+Kz7VkafAXHRSDixVfAWMI1tQrxoOpVn96pzCSw JJzTKxjqE6TVitA9iAlK7rLhdPVQDoHVxJx98LZij6mhFRdkTSvG0p9Y14AYlqr+FcGYWlXvgf 8Huv2gtD8xbKP8tgpIJobBe3UEBzIaSMfw59Iq95JXvEBQCrKu9R/91zu10CYLBqRpf08TkISU eYtTAzmKBPdpPbQbEM1YmaxC Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2020 18:03:49 -0700 IronPort-SDR: 0xwe56tlmAZW2U/SltKb3aBDh14ylBm7OPKNTOLhjazsqJCj2FvlohuF7PHqj9wFIvTKW6hHxR /fulnA4OJlYVqo/P23e5HNV8UTxFUiyz/BjBC09wtRF/5sSMI/Mkrx1V+NvSoBUKdcglnOdHlY ff+5Ka4l2utoVILnfqa5ugp+Hg3MaYYuV1ZR0ESxsI3UcW8FAoz1ZvWw/HyMGQTpspspbfswz7 QzFEq7YmjpIy5WOLaNoSpUnFfD0cA9rsdoXuIFYEv/Z9INmXxR35ysQi6wBDt8ejxK5OlesVuV ReE= WDCIronportException: Internal Received: from mccorma-lt.ad.shared (HELO yoda.hgst.com) ([10.86.54.125]) by uls-op-cesaip01.wdc.com with ESMTP; 17 Mar 2020 18:11:59 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Anup Patel , Albert Ou , Gary Guo , Greentime Hu , linux-riscv@lists.infradead.org, Mao Han , Mike Rapoport , Nick Hu , Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Vincent Chen , Zong Li , Bin Meng Subject: [PATCH v11 06/11] RISC-V: Move relocate and few other functions out of __init Date: Tue, 17 Mar 2020 18:11:39 -0700 Message-Id: <20200318011144.91532-7-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200318011144.91532-1-atish.patra@wdc.com> References: <20200318011144.91532-1-atish.patra@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The secondary hart booting and relocation code are under .init section. As a result, it will be freed once kernel booting is done. However, ordered booting protocol and CPU hotplug always requires these functions to be present to bringup harts after initial kernel boot. Move the required functions to a different section and make sure that they are in memory within first 2MB offset as trampoline page directory only maps first 2MB. Signed-off-by: Atish Patra Reviewed-by: Anup Patel --- arch/riscv/kernel/head.S | 153 +++++++++++++++++--------------- arch/riscv/kernel/vmlinux.lds.S | 5 +- 2 files changed, 86 insertions(+), 72 deletions(-) diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index 85f2073e7fe4..173507395a6b 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -14,7 +14,7 @@ #include #include -__INIT +__HEAD ENTRY(_start) /* * Image header expected by Linux boot-loaders. The image header data @@ -45,8 +45,85 @@ ENTRY(_start) .ascii RISCV_IMAGE_MAGIC2 .word 0 -.global _start_kernel -_start_kernel: +.align 2 +#ifdef CONFIG_MMU +relocate: + /* Relocate return address */ + li a1, PAGE_OFFSET + la a2, _start + sub a1, a1, a2 + add ra, ra, a1 + + /* Point stvec to virtual address of intruction after satp write */ + la a2, 1f + add a2, a2, a1 + csrw CSR_TVEC, a2 + + /* Compute satp for kernel page tables, but don't load it yet */ + srl a2, a0, PAGE_SHIFT + li a1, SATP_MODE + or a2, a2, a1 + + /* + * Load trampoline page directory, which will cause us to trap to + * stvec if VA != PA, or simply fall through if VA == PA. We need a + * full fence here because setup_vm() just wrote these PTEs and we need + * to ensure the new translations are in use. + */ + la a0, trampoline_pg_dir + srl a0, a0, PAGE_SHIFT + or a0, a0, a1 + sfence.vma + csrw CSR_SATP, a0 +.align 2 +1: + /* Set trap vector to spin forever to help debug */ + la a0, .Lsecondary_park + csrw CSR_TVEC, a0 + + /* Reload the global pointer */ +.option push +.option norelax + la gp, __global_pointer$ +.option pop + + /* + * Switch to kernel page tables. A full fence is necessary in order to + * avoid using the trampoline translations, which are only correct for + * the first superpage. Fetching the fence is guarnteed to work + * because that first superpage is translated the same way. + */ + csrw CSR_SATP, a2 + sfence.vma + + ret +#endif /* CONFIG_MMU */ +#ifdef CONFIG_SMP + /* Set trap vector to spin forever to help debug */ + la a3, .Lsecondary_park + csrw CSR_TVEC, a3 + + slli a3, a0, LGREG + .global secondary_start_common +secondary_start_common: + +#ifdef CONFIG_MMU + /* Enable virtual memory and relocate to virtual address */ + la a0, swapper_pg_dir + call relocate +#endif + tail smp_callin +#endif /* CONFIG_SMP */ + +.Lsecondary_park: + /* We lack SMP support or have too many harts, so park this hart */ + wfi + j .Lsecondary_park + +END(_start) + + __INIT +ENTRY(_start_kernel) /* Mask all interrupts */ csrw CSR_IE, zero csrw CSR_IP, zero @@ -134,59 +211,6 @@ clear_bss_done: call parse_dtb tail start_kernel -#ifdef CONFIG_MMU -relocate: - /* Relocate return address */ - li a1, PAGE_OFFSET - la a2, _start - sub a1, a1, a2 - add ra, ra, a1 - - /* Point stvec to virtual address of intruction after satp write */ - la a2, 1f - add a2, a2, a1 - csrw CSR_TVEC, a2 - - /* Compute satp for kernel page tables, but don't load it yet */ - srl a2, a0, PAGE_SHIFT - li a1, SATP_MODE - or a2, a2, a1 - - /* - * Load trampoline page directory, which will cause us to trap to - * stvec if VA != PA, or simply fall through if VA == PA. We need a - * full fence here because setup_vm() just wrote these PTEs and we need - * to ensure the new translations are in use. - */ - la a0, trampoline_pg_dir - srl a0, a0, PAGE_SHIFT - or a0, a0, a1 - sfence.vma - csrw CSR_SATP, a0 -.align 2 -1: - /* Set trap vector to spin forever to help debug */ - la a0, .Lsecondary_park - csrw CSR_TVEC, a0 - - /* Reload the global pointer */ -.option push -.option norelax - la gp, __global_pointer$ -.option pop - - /* - * Switch to kernel page tables. A full fence is necessary in order to - * avoid using the trampoline translations, which are only correct for - * the first superpage. Fetching the fence is guarnteed to work - * because that first superpage is translated the same way. - */ - csrw CSR_SATP, a2 - sfence.vma - - ret -#endif /* CONFIG_MMU */ - .Lsecondary_start: #ifdef CONFIG_SMP /* Set trap vector to spin forever to help debug */ @@ -211,16 +235,10 @@ relocate: beqz tp, .Lwait_for_cpu_up fence -#ifdef CONFIG_MMU - /* Enable virtual memory and relocate to virtual address */ - la a0, swapper_pg_dir - call relocate + tail secondary_start_common #endif - tail smp_callin -#endif - -END(_start) +END(_start_kernel) #ifdef CONFIG_RISCV_M_MODE ENTRY(reset_regs) @@ -301,13 +319,6 @@ ENTRY(reset_regs) END(reset_regs) #endif /* CONFIG_RISCV_M_MODE */ -.section ".text", "ax",@progbits -.align 2 -.Lsecondary_park: - /* We lack SMP support or have too many harts, so park this hart */ - wfi - j .Lsecondary_park - __PAGE_ALIGNED_BSS /* Empty zero page */ .balign PAGE_SIZE diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S index 1e0193ded420..b32640300d07 100644 --- a/arch/riscv/kernel/vmlinux.lds.S +++ b/arch/riscv/kernel/vmlinux.lds.S @@ -10,6 +10,7 @@ #include #include +#include OUTPUT_ARCH(riscv) ENTRY(_start) @@ -20,8 +21,10 @@ SECTIONS /* Beginning of code and text segment */ . = LOAD_OFFSET; _start = .; - __init_begin = .; HEAD_TEXT_SECTION + . = ALIGN(PAGE_SIZE); + + __init_begin = .; INIT_TEXT_SECTION(PAGE_SIZE) INIT_DATA_SECTION(16) /* we have to discard exit text and such at runtime, not link time */ -- 2.25.1