Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp6374030ybv; Wed, 12 Feb 2020 10:59:38 -0800 (PST) X-Google-Smtp-Source: APXvYqwBaHIxEWIKIXz5QLShnB5ewkRIqwjynrGRfG6/B1sp2fzFBIqrqrBuUUf0kS/7pH+yhXJP X-Received: by 2002:aca:1708:: with SMTP id j8mr354793oii.166.1581533978075; Wed, 12 Feb 2020 10:59:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581533978; cv=none; d=google.com; s=arc-20160816; b=hY2+KSEWsyhFPziXSLB6mO8bhdSLNF/yLahZD3Tv39se6FiECzgewY3Ri12Lj8L2Z4 9dToDNQ2RpiqlV11L95UJ+penrsoTpBaO2eRaqGUv6ZMyzViQf0ddx2VZsm6JnPDgh6W JU7aDx/teoMtjRFkd+JYtRTVQOfcpX3s3Vx/pQ/he0M6nQFff7FwYcGzoCQyjRPXUxC7 As+Eqkonp1gG4F0QWUrwjnTbdxuNEAZJkmQTSy+JAsmtmSrG5qBWMqlglced/u2oMO9i DEQ1XtOM9Ag86gYfm8EOGmmUxZ8WQNV8nr97QXj68qaA1AAHzmnwej1DHhG9ehXFAxWf 8ZaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=4iWpjS84iXuZKMy6ZUtTecttvvwiEglLKnXkpaETIX4=; b=Z00aXDUHR679wnfWUdaAEWY1o1xXvTdwDyWhnuo/QVY535qQi0MT5m1q00KVMXe3Dm yyc3M+nXmWsNw1Dm52nM0+FawZIBUzP9GTLNnwW7RqElHuE9JBlEWxJhxmDvfoTR3mLO YGq1YRFKoEQYSdXKFBiyJCKBdUY65d4Zz+ABaonK1jI69rdmsj2JLGhuA0myNIGLH2Bi pfphYBb3ouRCNRWSAMiIe46nvYBmcK5sofYu9Wk5sAq3Ne2ic8v8Dc9PxKjV0EIKVpc5 XwQlbJWDZsSxYvfoonutls+t0wdj8sqfu0tgU+ytskXN+TK1bXP3uGl7XNhos9w2gyyj /Q9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=YUiQw1hm; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k1si3865754oic.245.2020.02.12.10.59.25; Wed, 12 Feb 2020 10:59:38 -0800 (PST) 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=pass header.i=@atishpatra.org header.s=google header.b=YUiQw1hm; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728986AbgBLS7J (ORCPT + 99 others); Wed, 12 Feb 2020 13:59:09 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:37282 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727054AbgBLS7I (ORCPT ); Wed, 12 Feb 2020 13:59:08 -0500 Received: by mail-wr1-f65.google.com with SMTP id w15so3711198wru.4 for ; Wed, 12 Feb 2020 10:59:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4iWpjS84iXuZKMy6ZUtTecttvvwiEglLKnXkpaETIX4=; b=YUiQw1hmb0MdD9htXyE7jU5pynWAVmivpNXH4tuPdrqeisAZUhAKzcEgZiBMfUOBiE 91EKvU5ZYR5yY98VUkYUmylI5porAO83ZhoNvh3ZD7X+z0NLzm+QIcizro8jdkpY+qj8 UO7a3Q9RRKUpoCNzKzZOp5HxNZ3hTUmOgARcuDGMK6esrF+io8cRjMeDMHtvPkhymmpn 4Cz4RtLXcpAIHwhsRBMsYrNcIbsb1G3sYADnadb/qMGnAiJPYQH4yiJ6+QFcOCRS5xDl woLTOWSyDvDZr9nwP4h0K+5ZiUTf6EIT7D1/0UBeiWWIEwz6funXEfZvJ/8h7nGQEIK8 6PZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4iWpjS84iXuZKMy6ZUtTecttvvwiEglLKnXkpaETIX4=; b=E7bw2jiF5OX/EeIySjg85MxLfScJj4qD591oQPnErY1MRP3cQcoYuCEv9ZHY03W/za AK5+5uOexPaNvNXgcqi3lZ+QC+WzWwEfNHReyZ//0Kvd1l5AnkS/1LCd6QvrcA4cdXiO 83R02/OUSs+znjVWy2wIRFuXQiAPlho0Pljvwp8GIPf2paCnzgnaa/ds88qI3qzSlJYn eBOKfVxmV6DBGgG6+3HOjJ6Azf8Y9C9jyuPv8vl2gXGQ9ep25wiOJzNRURG5dq9OAZFA YyC77+ceeV8OZdByXwcaA3N0+Z70JJ3kqWP+49J1mH2coceGuWA1SfRW9ig2sp9ctJTg 64GA== X-Gm-Message-State: APjAAAVero3Mp+/2I5lLub1AIa/IvozIL1hQMt22wI/Zl2rG87mtmvdb nIUL+2zs1yLUEXli5KsqChAt+LxYI6Q81mC2J/3q X-Received: by 2002:adf:f507:: with SMTP id q7mr16342704wro.384.1581533945683; Wed, 12 Feb 2020 10:59:05 -0800 (PST) MIME-Version: 1.0 References: <20200212014822.28684-1-atish.patra@wdc.com> <20200212014822.28684-7-atish.patra@wdc.com> In-Reply-To: From: Atish Patra Date: Wed, 12 Feb 2020 10:58:54 -0800 Message-ID: Subject: Re: [PATCH v8 06/11] RISC-V: Move relocate and few other functions out of __init To: Anup Patel Cc: Atish Patra , Albert Ou , Jason Cooper , Marc Zyngier , Daniel Lezcano , Heiko Carstens , "linux-kernel@vger.kernel.org List" , Mike Rapoport , Vincent Chen , Mao Han , Geert Uytterhoeven , "Eric W. Biederman" , Paul Walmsley , Michael Ellerman , Marek Szyprowski , Palmer Dabbelt , linux-riscv , Borislav Petkov , Thomas Gleixner , Allison Randal , Kees Cook Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 11, 2020 at 8:18 PM Anup Patel wrote: > > On Wed, Feb 12, 2020 at 7:21 AM Atish Patra wrote: > > > > 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 sections > > I think you meant "... require these functions" here. > > > to be present to bringup harts after initial kernel boot. > > > > Move the required sections to a different section and make sure that > > Same here, I think you meant "... the required functions to a > different section ..." > My bad. Thanks for pointing out. Fixed. > > they are in memory within first 2MB offset as trampoline page directory > > only maps first 2MB. > > > > Signed-off-by: Atish Patra > > --- > > 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 a4242be66966..c1be597d22a1 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 > > @@ -125,59 +202,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 */ > > @@ -202,16 +226,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) > > @@ -292,13 +310,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 12f42f96d46e..18c397953bfc 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.24.0 > > > > Apart from above nit in commit description, looks good to me. > > Reviewed-by: Anup Patel > > Regards, > Anup > -- Regards, Atish