Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp3391138img; Mon, 25 Mar 2019 09:19:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqyNwTc/13y3fN4FTjuKkpuJ3d6BFG9eZTydYAus4py6JRXm0hbBEshcKbTQWsTFMmTO3YjC X-Received: by 2002:a17:902:be04:: with SMTP id r4mr12605775pls.218.1553530777661; Mon, 25 Mar 2019 09:19:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553530777; cv=none; d=google.com; s=arc-20160816; b=BmaexE6/Dr85gtVKn9hcOTA+hq64cZmuufsiG7ZLtvbUzdZVXeco9C2EClFX+m7K4c CIDeCGMm7LiCmmmVV/ows13w7nuTitj4DvYaA/1g7bzBzhUUS4wj4RcEurok9wjJwxDq CQEqPXj41Pi9EIWYFVhsKJQ0ue4fAxjq08HuX3V1+YiEoC/MHjyKcPUVtN9Maiul/ccD hN+seqloipiYtJufo4EjuAvfQuhilbBRKgwd8/Ym6orACr9RKZFxbPz29cN9EgAjjZgA rYMksrs2a+/gk8mdgF5JuOM5wJJ3tZ8STYUgMgip68omv+9YWjZvZyWVMOAJOutrc8Cu Nd+g== 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=3OCmxubdP2nbG77xoMJhNUuIbCr81ZRpBEz8MY/sedY=; b=pz28ubaLbBhKwkcDmOFMzO7PsoY7m/8uZic9JEnpYXz6kiNGcu9kBhACK/av3H7MXw pM/zkn2SK4Lea9tUdAu0cRLn9ARNMr8mtq3alXR+EAJBU6pi+p4uCNJ7gb8NYjj8Jp1M rL4npkf+D5jH1m85yRwn29bwh3haYmG3CnuL9FPIEqKFrHnA08M4mCA/T02a4KLBUARQ MYGjvm592H5IZPvBJzUI7W+NtjWwxioYViAJDS9XuEatKlU6+uSXEHXd5D1Xy9uJojRz fnLM0KCtT1sIFYon/sj0jIquEUwShIHkx4f5AfkZw7xXNtQjRsA+807oo5V3ua9TMAdu Vp0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=fkz8R3nF; 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 g2si11228009pgc.225.2019.03.25.09.19.22; Mon, 25 Mar 2019 09:19:37 -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=fkz8R3nF; 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 S1729283AbfCYQRM (ORCPT + 99 others); Mon, 25 Mar 2019 12:17:12 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:33698 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726182AbfCYQRL (ORCPT ); Mon, 25 Mar 2019 12:17:11 -0400 Received: by mail-wr1-f68.google.com with SMTP id q1so10900600wrp.0 for ; Mon, 25 Mar 2019 09:17:10 -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=3OCmxubdP2nbG77xoMJhNUuIbCr81ZRpBEz8MY/sedY=; b=fkz8R3nFiYXZ5FV4x8L6CwBRZiNK8Ot9sdcN3g3MzXMsrPlZd6PcjbRzgnuY8kE1OS /hcJIEHKEgY9ZGCE5NpAcJgGfKVo30avcrBhBypPlOzFiCEHFfzYRVFOYN5OLQhQEkap d4wvo8GhNDJAqEpGyCgoWgsAnxiNMRFUd9b3icZYilCh7AtAJp/wo2s1nzDABq7nsXkw ls/MGbksqpmCHJynL2YuEhTz/cro1i3+X0KW/STI7EKiwi9S5WB/tCM3VpVATZJiDQA/ DQjDvsn8L9TRXZYE/vQAyer+MrGJ0F5Ybs7kJjqBmZfmrD8Fx4tw2Uu6prviXMZww1sK /g2A== 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=3OCmxubdP2nbG77xoMJhNUuIbCr81ZRpBEz8MY/sedY=; b=Y0ySQspb4jeuhl3Ko4r5x27gmPSoSNVuqZ+44YuXKmaYZIG59A8DUWV55jlC3Z9xc8 xHxLv4t/Zp9QN+/sj+O/lo6ZLnqD+RfoqjLok+kTMirD0Hbj1NGAonPaSzFkX4gQ10B8 ELnZk7RckRrUhIasdbp4D9u6zdu96TgEF2ETyELHQ24MZKN0Ld6I8LelYOLFDzXV/IAG cbnpFgcta0j1TKZvjmNrtPcO9I6iuy4RP95nWWolF1RwW6nPDrtBSgxRZLcp5tPgXobj 56EJCC9jplnNKVtbU0GtsFrxf1FA2SerJa9qH6YQZaJszuaBKtmOAQP9izEcy63Q9VR6 13kA== X-Gm-Message-State: APjAAAXd5A8v7aHYwOUlljQXeYZbfAqdDryyeoNJKZxxKYdkOQxnHJHP 50nFo2kGVvHe1msnO+6MXqAbW9BfLV8UWWJHFhcfNg== X-Received: by 2002:a05:6000:120c:: with SMTP id e12mr2653855wrx.187.1553530630082; Mon, 25 Mar 2019 09:17: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> In-Reply-To: <20190325145919.GB14826@infradead.org> From: Anup Patel Date: Mon, 25 Mar 2019 21:46:59 +0530 Message-ID: Subject: Re: [PATCH v3 4/4] RISC-V: Allow booting kernel from any 4KB aligned address To: Christoph Hellwig Cc: Anup Patel , Palmer Dabbelt , Albert Ou , "linux-kernel@vger.kernel.org" , Mike Rapoport , Atish Patra , Paul Walmsley , "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 Mon, Mar 25, 2019 at 8:29 PM Christoph Hellwig wrote: > > On Mon, Mar 25, 2019 at 06:18:45PM +0530, Anup Patel wrote: > > We trying to addresses following issues in current code: > > 1. The current setup_vm() maps all possible kernel virtual addresses (128GB > > on 64bit system and 1GB on 32bit system). The amount RAM present on > > real systems might be much less so we should not have kernel mappings for > > non-existent RAM. Of course, we don't know amount of RAM available in > > setup_vm() so we have to split page table setup in two parts and do minimal > > required mapping in setup_vm(). > > 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. Above things add more debugablity to kernel and also help us catch bugs faster. > > > 2. NOMMU kernel requires a swapper_pg_dir with identity mapping (VA == PA) > > Bullshit. nommu per defintion does not have page tables, and thus Yes, I know but we did see a kernel crash in-absence of kernel page table with identity mappings. > > > 3. For both NOMMU with tiny memory and MMU with tiny memory, the current > > setup_vm() is not allowing us to place kernel on non-2M (or non-4M) aligned > > addressed there by causing memory below kernel to be wasted. > > As mentioned a few times - nommu per defintion does not have page > tables, and in my uptodate nommu port none of this code is even compiled > in. If someone still compiles that code in some codebase that is just > a bug that needs to be fixed. > > For MMU with tiny memory is is a theoretical case, but I still haven't > seen a good rationale why we'd care for that case. Lot of RISC-V systems being built today target resource constraint use-cases (such as IoT or embedded) where more RAM is more cost and more power. It is very useful to have Linux RISC-V run on just few MBs (if possible). > > > 4. For MMU based kernel, the current setup_vm() is hard-wired for fixed 2M > > mapping size. It will require more changes if we want to do 1G mappings. > > And why do we care? Even if we come up with a good reason for 1G > mappings we'd better find a way to select it at run time and not require > a gazillion of options to select how to map the kernel. 1G mappings will give better performance compared 2M mappings. This will be very useful for performance hungry system with lot of RAM. This patch selects 1G or 2M mapping at runtime based on load address alignment. Regards, Anup