Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp302597ybb; Thu, 28 Mar 2019 02:54:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqzfWglfal4mtua7rB7NrcNnV6Z+Eh1NXuOLapDLR0wungPLi10yRJgK3LJ4jkaSoxN5Ao5P X-Received: by 2002:a17:902:1c9:: with SMTP id b67mr40717650plb.176.1553766846361; Thu, 28 Mar 2019 02:54:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553766846; cv=none; d=google.com; s=arc-20160816; b=RUKN7YC4Ogw0dTvmkO38AkfZspl4NfCYJxSF+QdqkEgXViwGEg28EoDD0D4dGECmCB XwIPEEajXPuke3hyb5Prv+TbKwGOn0KTPWnTFmGsK/VqgttMk6krWZbxeU3+jszAWgLd XWc4qRD7M3gFeu8wV0Cc8bMxqQ6FrX3k+V0wh37tua2QBH0kEPjN9Kn0xSq//cxr1LZr JZUmsBzNjazYZ+qAporlq8nEhv77mfcs3BlBdHJV4EmkjEoIvO3uC1+9pOhzZkdIJEgO u+Oe4FsuTzhPGKbm8Q4nbVJBUxZcwD/cDMsSP1Mfo7ufafON0v61t77SgRHy6KrpISfD Zq0Q== 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=LhA1qdRHEXWJUF9ewlQbprtaxlTvnHssd0Yr2vmSUhU=; b=hyM2Ddv5H0f83cwdG6bdQ6E5uo5JMnVi0etBrsi4sKXfYtfiLuEyelz6pY16Rfh9AU MrDL+SWttOWOoLndBnogPG0LbTwcTI1KHu3F+puzVpDx3VSlP3rPWLh76bSKSnSzSxMd yiYespNx4MaQJuhvvZcaefnyTOaSlPFmiZ01N5AtkX9FmWG27HwLcIYQdNX35YM5b2GZ VtZSRp8tKEicz1LWFBqZqHOl62dKe0x6MhG6j/xfowIrCjBp+Hog2DuM+jpXiPNdWc3p ToizaKI9E3eDWh8Uy6SJTYA5nEUSfTHMtqqpketS1FcY6rn36NrInKLD2seUw3bDO7le hZ4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=BYMulcOU; 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 c142si8372520pfb.32.2019.03.28.02.53.50; Thu, 28 Mar 2019 02:54:06 -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=BYMulcOU; 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 S1726200AbfC1JxM (ORCPT + 99 others); Thu, 28 Mar 2019 05:53:12 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:34284 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725846AbfC1JxM (ORCPT ); Thu, 28 Mar 2019 05:53:12 -0400 Received: by mail-wr1-f66.google.com with SMTP id p10so22057050wrq.1 for ; Thu, 28 Mar 2019 02:53:11 -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=LhA1qdRHEXWJUF9ewlQbprtaxlTvnHssd0Yr2vmSUhU=; b=BYMulcOUPLgEeyeLI4wbm/JXS9MwOLz5b7TIjN2cpUB5w1g9mekqEdnF45oAyH2mDM uXLL1XYXzsAg3AqmLb+iwleGyQ4ngjZ8YRIUKKx5c4sGYZy14Rhygmd/5u62uduuBeR7 F+mc2Cu8sm450bIPpaJQnDQ+agIMi0S76TeVZwTTMIVUGUCbxChPxnz+t/SEteGBesg7 LeNJwSOlhu8LKPfDENdCGuIqQLM/Dwn0mpgdLreLRPZbhXDOgG64RHdte6oijZS0vyEd x/g/HRqow+V6B4o0gd1+dJmZqjdYjdpCnp4Hl22mm8jhRpu0GMC9pMB4CBxB+LDJ2R7R 6rUA== 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=LhA1qdRHEXWJUF9ewlQbprtaxlTvnHssd0Yr2vmSUhU=; b=DGwKugGBwTtUm6JOZsX/JdyVDzqkWMktcdtzubmS0PJj6bIu8NZMV8b9eh6j5kZ2p3 0b0KVXSpvtirpCk8K+sp/Q7havrajQAT4xNCukgnv0083bQQigBYiQfY71ym6hjugU3r jflf5Rn7YYpdkV7++kZChd7ixDXCMYFjONEMR33wy8PTbmwqN1IooVt73yU+PFXIbSEf BX16py83XjlycEPijgZE85wxLTCwYREhpDvvIE1bSfs2g+3EVfJXf48RYX5pn+VRNvaI E7LHAJAJ3VnuFV5/s1fHlTvTlHlCSaXL3XinI1fonJVN5O0yz2jigJ1ZhlB6EYO2wD+Q L6XQ== X-Gm-Message-State: APjAAAVseWX7GjHsOyIQFFSx+PpQGRAT7n4qYRBP71YPA4q8FpNbXp+P RbVEWcFpAM0tvcc9nh6bMynlHNMCwEcr5y3yub5i2UhCokg= X-Received: by 2002:adf:9427:: with SMTP id 36mr27906412wrq.128.1553766790178; Thu, 28 Mar 2019 02:53:10 -0700 (PDT) MIME-Version: 1.0 References: <20190325092234.5451-1-anup.patel@wdc.com> <20190325092234.5451-5-anup.patel@wdc.com> <20190325113935.GD27843@infradead.org> <20190325145919.GB14826@infradead.org> <20190327075441.GA29894@infradead.org> <20190328075526.GC14864@rapoport-lnx> In-Reply-To: <20190328075526.GC14864@rapoport-lnx> From: Anup Patel Date: Thu, 28 Mar 2019 15:22:58 +0530 Message-ID: Subject: Re: [PATCH v3 4/4] RISC-V: Allow booting kernel from any 4KB aligned address To: Mike Rapoport Cc: Christoph Hellwig , Palmer Dabbelt , Anup Patel , "linux-kernel@vger.kernel.org" , Atish Patra , Albert Ou , Paul Walmsley , "linux-riscv@lists.infradead.org" , me@anthonycoulter.name 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 Thu, Mar 28, 2019 at 1:25 PM Mike Rapoport wrote: > > On Wed, Mar 27, 2019 at 12:54:41AM -0700, Christoph Hellwig wrote: > > On Mon, Mar 25, 2019 at 09:46:59PM +0530, Anup Patel wrote: > > > > Why do you even care about kernel mappings for non-existant ram. > > > > > > We care because there will always be some buggy kernel driver/code going > > > out-of-bound and accessing non-existent RAM. If we by default map all > > > possible kernel virtual address then behaviour of buggy accesses will be > > > unpredictable. > > > > > > Further, I think we should also make .text and .rodata sections of kernel > > > as read-only. This will protect kernel code and rodata. > > > > All of that is useful at the final_setup_vm() time - but none of it > > matters during early setup_vm where life is complicated. > > > > Mike suggested on the previous iteration that you only do smaller > > mappings when setting up the final mapping to avoid the ops churn, > > and I fully agree with him. > > > > So I would suggest we avoid complicated the fiddly early boot changes > > that just add complxity, and you instead redirect your efforts to > > say implemented proper ro and non-executable sections using 4k mappings > > in the final VM setup only. That should actuall lead to less code > > and complexity, and provide more benefits. > > It might be worth keeping trampoline_pg_dir if we are to split setup_vm(). > Then setup_vm() will only initialize the trampoline_pg_dir and > final_setup_vm() will setup the swapper_pg_dir and switch to it. > Otherwise final_setup_vm() would need to update live mappings which might > be fragile. > We finally know the purpose trampoline_pg_dir page table. The trampoline_pg_dir is suppose to contain only one 2M/4M mapping to handle case where PAGE_OFFSET < load_address. For 64bit systems, the PAGE_OFFSET is very high value typically 0xFFFFxxxxxxxxxxxx compared to RAM start 0x80000000. It is very unlikely that we will have enormous RAM ending somewhere 0xFFFFxxxxxxxxxxxx. For 32bit systems, it is quite possible that bootloader loads kernel at load_address > 0x80000000. Let say PAGE_OFFSET = 0xC0000000 and load_address = 0xC0100000. Now the instruction which enables MMU will be 0xC0100xxx and after enabling it will try to fetch next instruction 0xC0100xxx + 4 but 0xC0100000 maps to 0xC0200000 as load_address > PAGE_OFFSET hence we will see wrong instruction after enabling MMU. (Note: Above explanation was provided by Anthony) I guess we will have to keep both trampoline_pg_dir and swapper_pg_dir init in setup_vm() because trampoline_pg_dir will only contain just one 2M/4M mapping. Regards, Anup