Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp317737ybl; Thu, 15 Aug 2019 18:07:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqzLgmTloQiH+WLT8w0UDLfaZ6UQ4Jv5r7odFqsTqy+R+wuHTkndCnB5elDG2AD9z+et9ZeA X-Received: by 2002:a63:60a:: with SMTP id 10mr5526404pgg.381.1565917671119; Thu, 15 Aug 2019 18:07:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565917671; cv=none; d=google.com; s=arc-20160816; b=D19zS0OtWMB/paee3rmSufVUcLa6+ZRb3//OQJneJttblTcaa5J1eUrPS3GhW2KETv 7D2ikKr3AvbiOW3Wvhq1dap6fK60sCL9PenMYNOzNNjD+LWWCfhz3rCfHuW6V8zgwCaP c4i1Y5LGijStPfGI4DbYuhmIMC46OFWoG/PXuhBGzqEZ+6GRjP0jyfjI2CJvRwuwm+LS w0+3ei4moYrTvKfhAvbtHJPoaZISH0ehOkwOc+aMFthmxzIzLxYDzdZZsUxP45pkiwtm ADYx58eXwfPoe1hrqEjAlxdcoEn+2VtDZpG8/7JLKM/42r/pcFOsyw/ey83474X8ZW8b FDLg== 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=7Ip/v0TDAZjAfpcFjyW7SV7ckK6aXUGiD3K/tBldql4=; b=D9BWEZ+Rkw1gpxlvUf7xaqjckTuUJ45RDi491IBGGhu5TaBW6xVKxor9y3NW+ACRIB 6fu5sQJ9zzc25w6f7Dj9ZaMq9xdjarWvcPApvTuYEBMIpMFklpzmseODTV21TqJ1Mz84 4PO3ldUvGJkgCzRnEBktjqUx7nTvVyiXYqZzWSIy68CT9JVCiRu/qmymIGeNZrca9Z4a DI/V4gNte5Wev1pmZ7mlem2X265iEkusiBHV8YZDuaWKJ5h7djEbn2cm9tR7+FauI5rA lpt5kddGN1d0B6jLQpCUxANuksvCJMhpMQxN9WOP3iSeHyHayHbctD1chQ5SxdKy1W3v x4Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=qpeJdpG1; 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 l186si2716378pgd.455.2019.08.15.18.07.34; Thu, 15 Aug 2019 18:07:51 -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=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=qpeJdpG1; 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 S1726457AbfHPBFW (ORCPT + 99 others); Thu, 15 Aug 2019 21:05:22 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:50577 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725983AbfHPBFW (ORCPT ); Thu, 15 Aug 2019 21:05:22 -0400 Received: by mail-wm1-f68.google.com with SMTP id v15so2732145wml.0 for ; Thu, 15 Aug 2019 18:05:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7Ip/v0TDAZjAfpcFjyW7SV7ckK6aXUGiD3K/tBldql4=; b=qpeJdpG13aFoxjEPvKIUGZh40x293gnmRJs1KuI6t8G/qdjkI/1T0S6Lyb1R8qTt8P DDg5xtB+oxFjqlql5EHw1xOWq3QeJW8ggkdULwYHv6Nim+okbLvl1FaBOdAthwXdQXTV 2E/b9nz/8DD6RbicdU3yIa9wgJavZIbrycIH57DHvQG1LulafEe63lBOL9L01ighvIhY VOkFzE2/ilBmElWqMvJ/E2QXeg2FceVcpcTOXimnK7ZOJuxHL+Wj6KRsMwslz2YMw1it FIffhuHFM90rvB61Wb6gGqvEdDVdP3bQ2QrZLe5cQGlxnQ6AruC423KludMKaIqv86BI w9Kw== 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=7Ip/v0TDAZjAfpcFjyW7SV7ckK6aXUGiD3K/tBldql4=; b=jYAgts4sVSyBsueyu14d43oty5URVGcfXC8sA/YorYaz/T6el2lY8AndXYDk2X7lVM MsdIHW0QIgcQae7aGYbdZDpXJZ7AGKaEaE2ZnWL+8zCymCUW48T7I1uFCNLqeaa/Rbxl wil53ozMndvhH6lFmhtfbs6ZXu7Q5b/mBZLeydIqGvkdCVBQSPzLtksKY/aNO6j0lmJJ KqpJJydOw12zwxwa/0YXut7Y+EW4FgvAlFBvV3SFGI7eQsTmoqWmTVAfQ5WSCh8KfGeH lQbrkwwq/QmQW7krlq+I+79jFUsf+YzEPOgHuE4E88UkZhXl/Ul/9g4cBTPbGcA2rKz6 ZRcw== X-Gm-Message-State: APjAAAUbExLWdR7sPOG5M37NVI7q68eUTFBqrVoUnejXb3JP1ChkwsLk MCZaoXmXcoqSpmYgbLLX5pT2DsxMt3jCB3IgvBF06g== X-Received: by 2002:a1c:be05:: with SMTP id o5mr4830082wmf.52.1565917519455; Thu, 15 Aug 2019 18:05:19 -0700 (PDT) MIME-Version: 1.0 References: <20190607060049.29257-1-anup.patel@wdc.com> <20190607060049.29257-3-anup.patel@wdc.com> <847fb8c879bbd2c3fd41dc1e428b3217253acebb.camel@wdc.com> In-Reply-To: <847fb8c879bbd2c3fd41dc1e428b3217253acebb.camel@wdc.com> From: Anup Patel Date: Fri, 16 Aug 2019 06:35:09 +0530 Message-ID: Subject: Re: [PATCH v5 2/2] RISC-V: Setup initial page tables in two stages To: Alistair Francis Cc: "paul.walmsley@sifive.com" , Anup Patel , "aou@eecs.berkeley.edu" , "palmer@sifive.com" , "linux-kernel@vger.kernel.org" , "rppt@linux.ibm.com" , "hch@infradead.org" , Atish Patra , "linux-riscv@lists.infradead.org" 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 Fri, Aug 16, 2019 at 12:27 AM Alistair Francis wrote: > > On Wed, 2019-07-10 at 17:05 -0700, Paul Walmsley wrote: > > On Fri, 7 Jun 2019, Anup Patel wrote: > > > > > Currently, the setup_vm() does initial page table setup in one-shot > > > very early before enabling MMU. Due to this, the setup_vm() has to > > > map > > > all possible kernel virtual addresses since it does not know size > > > and > > > location of RAM. This means we have kernel mappings for non- > > > existent > > > RAM and any buggy driver (or kernel) code doing out-of-bound access > > > to RAM will not fault and cause underterministic behaviour. > > > > > > Further, the setup_vm() creates PMD mappings (i.e. 2M mappings) for > > > RV64 systems. This means for PAGE_OFFSET=0xffffffe000000000 (i.e. > > > MAXPHYSMEM_128GB=y), the setup_vm() will require 129 pages (i.e. > > > 516 KB) of memory for initial page tables which is never freed. The > > > memory required for initial page tables will further increase if > > > we chose a lower value of PAGE_OFFSET (e.g. 0xffffff0000000000) > > > > > > This patch implements two-staged initial page table setup, as > > > follows: > > > 1. Early (i.e. setup_vm()): This stage maps kernel image and DTB in > > > a early page table (i.e. early_pg_dir). The early_pg_dir will be > > > used > > > only by boot HART so it can be freed as-part of init memory free- > > > up. > > > 2. Final (i.e. setup_vm_final()): This stage maps all possible RAM > > > banks in the final page table (i.e. swapper_pg_dir). The boot HART > > > will start using swapper_pg_dir at the end of setup_vm_final(). All > > > non-boot HARTs directly use the swapper_pg_dir created by boot > > > HART. > > > > > > We have following advantages with this new approach: > > > 1. Kernel mappings for non-existent RAM don't exists anymore. > > > 2. Memory consumed by initial page tables is now indpendent of the > > > chosen PAGE_OFFSET. > > > 3. Memory consumed by initial page tables on RV64 system is 2 pages > > > (i.e. 8 KB) which has significantly reduced and these pages will be > > > freed as-part of the init memory free-up. > > > > > > The patch also provides a foundation for implementing strict kernel > > > mappings where we protect kernel text and rodata using PTE > > > permissions. > > > > > > Suggested-by: Mike Rapoport > > > Signed-off-by: Anup Patel > > > > Thanks, updated to apply and to fix a checkpatch warning, and > > queued. > > > > This may not make it in for v5.3-rc1; if not, we'll submit it later. > > I'm seeing this failure on RV32 which I bisected to this patch: > > [ 1.820461] systemd[1]: systemd 242-19-gdb2e367+ running in system > mode. (-PAM -AUDIT -SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP > -LIBCRYPTSETUP -GCRYPT -GNUTLS +ACL +XZ -LZ4 -SECCOMP +BLKID -ELFUTILS > +KMOD -IDN2 -IDN -PCRE2 default-hierarchy=hybrid) > [ 1.824320] Unable to handle kernel paging request at virtual > address 9ff00c15 > [ 1.824973] Oops [#1] > [ 1.825162] Modules linked in: > [ 1.825536] CPU: 0 PID: 1 Comm: systemd Not tainted 5.2.0-rc7 #1 > [ 1.826039] sepc: c05c3c78 ra : c04b5a74 sp : df047ce0 > [ 1.826514] gp : c07a1038 tp : df04c000 t0 : 000000fc > [ 1.826919] t1 : 00000002 t2 : 000003ef s0 : df047cf0 > [ 1.827322] s1 : df7090f8 a0 : 9ff00c15 a1 : c072166c > [ 1.827723] a2 : 00000000 a3 : 00000001 a4 : 00000001 > [ 1.828104] a5 : df6f8138 a6 : 0000002f a7 : de62a000 > [ 1.828534] s2 : c072166c s3 : 00000000 s4 : 00000000 > [ 1.828931] s5 : c07a2000 s6 : 00400cc0 s7 : 00000400 > [ 1.829319] s8 : de491018 s9 : 00000000 s10: fffff000 > [ 1.829702] s11: de491030 t3 : de62b000 t4 : 00000000 > [ 1.830090] t5 : 00000000 t6 : 00000080 > [ 1.830392] sstatus: 00000100 sbadaddr: 9ff00c15 scause: 0000000d > [ 1.831616] ---[ end trace 49a926a1a5300c00 ]--- > [ 1.835776] Kernel panic - not syncing: Attempted to kill init! > exitcode=0x0000000b > [ 1.836575] ---[ end Kernel panic - not syncing: Attempted to kill > init! exitcode=0x0000000b ]--- > > Does anyone else see this? > > A simple revert of this patch on 5.3-rc4 fixes the issue for me. It looks like this patch is exposing some other bug of Linux RISC-V 32bit kernel. We will be hiding the actual issue by reverting this patch because previously we were mapping all possible kernel virtual addresses even for non-existent RAM (after RAM ends). Let me debug this more. Regards, Anup > > Alistair > > > > > > > - Paul > > > > _______________________________________________ > > linux-riscv mailing list > > linux-riscv@lists.infradead.org > > http://lists.infradead.org/mailman/listinfo/linux-riscv > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv