linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@linux.ibm.com>
To: Anup Patel <anup@brainfault.org>
Cc: Damien Le Moal <Damien.LeMoal@wdc.com>,
	Anup Patel <anup.patel@wdc.com>,
	Palmer Dabbelt <palmer@sifive.com>,
	Christoph Hellwig <hch@infradead.org>,
	Atish Patra <atish.patra@wdc.com>,
	linux-riscv@lists.infradead.org
Subject: Re: 32bit kernel is broken for Linux-5.1-rc1 due to GCC cmodel=medlow
Date: Fri, 22 Mar 2019 12:42:10 +0200	[thread overview]
Message-ID: <20190322104209.GB24367@rapoport-lnx> (raw)
In-Reply-To: <CAAhSdy0mUboGJH_GJbsGFBwcukjttVQcTGfzwkaMFQb9ZVY4Mg@mail.gmail.com>

Hi,

On Fri, Mar 22, 2019 at 11:46:24AM +0530, Anup Patel wrote:
> Hi Palmer,
> 
> The 32bit kernel booting is broken for Linux-5.1-rc1 due to GCC cmodel=medlow
> affecting setup_vm() movement from kernel/setup.c to mm/init.c.
> 
> There is no issue with 64bit kernel booting.
> 
> The "[PATCH v2 2/5] RISC-V: Make setup_vm() independent of GCC code model"
> fixes this issue.
> 
> https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1959102.html
> 
> If possible please include above patch as Linux-5.1-rc1 fix.

I'm not convinced that it's the best solution. Multiple __load_pa() and
__load_va() conversions make code unreadable.
Is there any reason swapper_pg_dir cannot be setup after 'relocate'? It'll
save a lot of churn for the current fix and for the addition of 4K mappings

I've drafted a patch that separates trampoline_pd_dir and swapper_pg_dir
setup, if it works, the __load_pa() and __load_va() conversions can be
applied only to the trampoline initialization. I don't have riscv hardware,
so it's compile tested only.

From d1f6f68012c84e188711954f58d63c0a3ba005c5 Mon Sep 17 00:00:00 2001
From: Mike Rapoport <rppt@linux.ibm.com>
Date: Fri, 22 Mar 2019 12:34:31 +0200
Subject: [PATCH] riscv: split trampoline_pg_dir and swapper_pg_dir
 initialization

Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
---
 arch/riscv/kernel/head.S |  7 ++-----
 arch/riscv/mm/init.c     | 33 +++++++++++++++++++++++++--------
 2 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
index fe884cd..fe0fc70 100644
--- a/arch/riscv/kernel/head.S
+++ b/arch/riscv/kernel/head.S
@@ -62,8 +62,9 @@ clear_bss_done:
 
 	/* Initialize page tables and relocate to virtual addresses */
 	la sp, init_thread_union + THREAD_SIZE
-	call setup_vm
+	call setup_trampoline
 	call relocate
+	call setup_vm
 
 	/* Restore C environment */
 	la tp, init_task
@@ -117,10 +118,6 @@ relocate:
 .option norelax
 	la gp, __global_pointer$
 .option pop
-
-	/* Switch to kernel page tables */
-	csrw sptbr, a2
-
 	ret
 
 .Lsecondary_start:
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index b379a75..1742763 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -187,11 +187,6 @@ asmlinkage void __init setup_vm(void)
 	BUG_ON((pa % (PAGE_SIZE * PTRS_PER_PTE)) != 0);
 
 #ifndef __PAGETABLE_PMD_FOLDED
-	trampoline_pg_dir[(PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD] =
-		pfn_pgd(PFN_DOWN((uintptr_t)trampoline_pmd),
-			__pgprot(_PAGE_TABLE));
-	trampoline_pmd[0] = pfn_pmd(PFN_DOWN(pa), prot);
-
 	for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) {
 		size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i;
 
@@ -209,9 +204,6 @@ asmlinkage void __init setup_vm(void)
 		pfn_pmd(PFN_DOWN((uintptr_t)fixmap_pte),
 				__pgprot(_PAGE_TABLE));
 #else
-	trampoline_pg_dir[(PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD] =
-		pfn_pgd(PFN_DOWN(pa), prot);
-
 	for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) {
 		size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i;
 
@@ -223,4 +215,29 @@ asmlinkage void __init setup_vm(void)
 		pfn_pgd(PFN_DOWN((uintptr_t)fixmap_pte),
 				__pgprot(_PAGE_TABLE));
 #endif
+	csr_write(sptbr, virt_to_pfn(swapper_pg_dir) | SATP_MODE);
+}
+
+asmlinkage void __init setup_trampoline(void)
+{
+	extern char _start;
+	uintptr_t pa = (uintptr_t) &_start;
+	pgprot_t prot = __pgprot(pgprot_val(PAGE_KERNEL) | _PAGE_EXEC);
+
+	va_pa_offset = PAGE_OFFSET - pa;
+	pfn_base = PFN_DOWN(pa);
+
+	/* Sanity check alignment and size */
+	BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0);
+	BUG_ON((pa % (PAGE_SIZE * PTRS_PER_PTE)) != 0);
+
+#ifndef __PAGETABLE_PMD_FOLDED
+	trampoline_pg_dir[pgd_index(PAGE_OFFSET)] =
+		pfn_pgd(PFN_DOWN((uintptr_t)trampoline_pmd),
+			__pgprot(_PAGE_TABLE));
+	trampoline_pmd[0] = pfn_pmd(PFN_DOWN(pa), prot);
+
+#else
+	trampoline_pg_dir[pgd_index(PAGE_OFFSET)] = pfn_pgd(PFN_DOWN(pa), prot);
+#endif
 }
-- 
2.7.4

 
> Regards,
> Anup
> 

-- 
Sincerely yours,
Mike.


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2019-03-22 10:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-22  6:16 32bit kernel is broken for Linux-5.1-rc1 due to GCC cmodel=medlow Anup Patel
2019-03-22 10:42 ` Mike Rapoport [this message]
2019-03-22 12:29   ` Anup Patel
2019-03-22 13:26     ` Christoph Hellwig
2019-03-22 13:38       ` Anup Patel
2019-03-22 13:25   ` Christoph Hellwig
2019-03-22 13:37     ` Anup Patel
2019-03-22 13:40       ` Christoph Hellwig
2019-03-22 13:45         ` Anup Patel
2019-03-23 17:21           ` Christoph Hellwig
2019-03-24  1:42             ` Anup Patel
2019-03-24  1:56               ` Gary Guo
2019-03-24  3:04                 ` Anup Patel
2019-03-24  3:10                 ` Anup Patel
2019-03-24  6:05                   ` Mike Rapoport
2019-03-24  9:41                     ` Anup Patel
2019-03-24  8:37               ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190322104209.GB24367@rapoport-lnx \
    --to=rppt@linux.ibm.com \
    --cc=Damien.LeMoal@wdc.com \
    --cc=anup.patel@wdc.com \
    --cc=anup@brainfault.org \
    --cc=atish.patra@wdc.com \
    --cc=hch@infradead.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@sifive.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).