Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp587004ima; Fri, 15 Mar 2019 09:24:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqx0tSgm8lPTP63y68XPGTnajaSQZ7jC2lchWA+4I6OW7GBPgWXrEn3ju8uSXAIP/huk5pzb X-Received: by 2002:a62:f51d:: with SMTP id n29mr4849268pfh.21.1552667058746; Fri, 15 Mar 2019 09:24:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552667058; cv=none; d=google.com; s=arc-20160816; b=ktZBYjMROCBuJ5uHDt1Md/U0DCacPbCMb5zlqNp0wqcx6HeErTV4AvyItR150hbfip kC57QW6HD2UrigU4T+56+QDq87gUHXhFWARBNtIkS1sNXbKen0ZpdCYsQFxz8cfyQ0UE irPZOTyBIbcDWToevXhEKrHUFg3W2YVlvaNfk9xMc8nBTMfyadp/JR5NkqJMKcmbqN32 9b4pg8YVM/DKb9n4ChFUyzOEL9V7dBNloPZMj55DRTVzAnL+qJZ4A4D1MvTZZ8PbAq+d AsZCssU87PawomFn6S0b1edL/euFZsa3DIIzYgp/QoEg/nHurHwgtvM2hnMyNw4FHa9f 7opw== 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=LDjj5RWEKhIkugf4FVrVXHHC2KLZaBYh2/nVjE3hmOA=; b=0dvQGS6j4ToXbIxXxKEJh4SD6xZehPHG/2itc7k2F7x2s4cdFtLexgpmRjK4ABkovs XQrF+8wlEz8rDuq7cpvTTaAS4Hvq+b0Z3DhfNdrVC428nfBtw68XhWoi9b7kSvI607jV YPySGKQzKXhEbSSaRECCayXb+cw8DVO1S9M43vVQy9r7L5pMriZNjCs6//fxA3zuELMt /Y6IRMXVfqjdE9DgnInQF3QUvs92H80b8uZPlDSA3TYbgygvI63T8Fl3R7GM5kUt505d CHGSHOZ3q4UdoblzqA0+reyOPbMBWxownuOQAjbmwn4K2lc2WNi3eoHlnQBRbCDOhFso YyjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=bnbn36AX; 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 e1si2052328pgs.451.2019.03.15.09.24.02; Fri, 15 Mar 2019 09:24:18 -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=bnbn36AX; 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 S1729525AbfCOQW7 (ORCPT + 99 others); Fri, 15 Mar 2019 12:22:59 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:34224 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726632AbfCOQW7 (ORCPT ); Fri, 15 Mar 2019 12:22:59 -0400 Received: by mail-wr1-f67.google.com with SMTP id k1so9709921wre.1 for ; Fri, 15 Mar 2019 09:22:57 -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=LDjj5RWEKhIkugf4FVrVXHHC2KLZaBYh2/nVjE3hmOA=; b=bnbn36AXBuz9JDIT8TjOMOHdMBqNCzKgrpwFDUmyHxP6Gv6suYegnXvzs++Y1t1VG0 P9dBAVbYhP3lqJf6NW3ZmUM9G22TVCUJiSfgdQothHKez3kVUGxQg1bXWbkZaaCksx4S MwJqVCBNARQCEZKlNbPHNFj0oVBZknemI5bxCSLlhf5oVVfsev74ol33G7avvGF9BJ11 JI/4thLhx+5lzSgxC6HGatqUoXbn1sIjrmbjZEHTpKBjutdDJWYqoOa/MBJQhTVINsys tXMFLmofNYE1eG4qXeDKplOii5QBNcGUvFZAVWahxNbIgESDXC/PIIV47aDHOYct+3NY wF6Q== 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=LDjj5RWEKhIkugf4FVrVXHHC2KLZaBYh2/nVjE3hmOA=; b=CiQEEJYdpqh3oZIbq4iHYAjoypE4TKeI0whnVJgsaW+uu/uXcJxouTh6yzfUTWpUST jxmyhNMQe/rOoZRZBbkw4mELVaWfNqTYMOerUn8Ipien3csiDwtKDs6/srGrFxdjzwwS THPufDkeW1s+R8w9Zt8B7O+nREx6JHXggOmy/3gA3l74rRgAypfp+TFC+Ahx4lm2/0g9 1CHc7qz/MqYzFeoARqPHbYf20u7KHSl90Z9IBuolgQOvw+jPcn2hkk4uN4JCB4v/lxLr QMAh02dWSnKRm/WubJ+Zs0pPzJ2Uz5CLDZSfGOzxPRLQ171Tgs+EzsxGOFGYpB/tFrsT 5pCA== X-Gm-Message-State: APjAAAXgmMx9sCPIBRQZa8M9k/Gx7KzWBIhq3Fr+V9T9BkWwN2I2FT1Y /tckkFthuwUIrktBZYqRkRtgjXLSxznSPXwVbb3xPw== X-Received: by 2002:adf:9427:: with SMTP id 36mr2141532wrq.128.1552666976612; Fri, 15 Mar 2019 09:22:56 -0700 (PDT) MIME-Version: 1.0 References: <20190312220752.128141-1-anup.patel@wdc.com> <20190312220752.128141-4-anup.patel@wdc.com> <20190313183121.GB28630@rapoport-lnx> <20190314065311.GC24380@rapoport-lnx> <20190315155828.GB920@rapoport-lnx> In-Reply-To: <20190315155828.GB920@rapoport-lnx> From: Anup Patel Date: Fri, 15 Mar 2019 21:52:45 +0530 Message-ID: Subject: Re: [PATCH 3/3] RISC-V: Allow booting kernel from any 4KB aligned address To: Mike Rapoport Cc: Anup Patel , Palmer Dabbelt , Albert Ou , Atish Patra , Paul Walmsley , Christoph Hellwig , "linux-riscv@lists.infradead.org" , "linux-kernel@vger.kernel.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, Mar 15, 2019 at 9:28 PM Mike Rapoport wrote: > > On Thu, Mar 14, 2019 at 11:28:32PM +0530, Anup Patel wrote: > > On Thu, Mar 14, 2019 at 12:23 PM Mike Rapoport wrote: > > > > > > On Thu, Mar 14, 2019 at 02:36:01AM +0530, Anup Patel wrote: > > > > On Thu, Mar 14, 2019 at 12:01 AM Mike Rapoport wrote: > > > > > > > > > > On Tue, Mar 12, 2019 at 10:08:22PM +0000, Anup Patel wrote: > > > > > > Currently, we have to boot RISCV64 kernel from a 2MB aligned physical > > > > > > address and RISCV32 kernel from a 4MB aligned physical address. This > > > > > > constraint is because initial pagetable setup (i.e. setup_vm()) maps > > > > > > entire RAM using hugepages (i.e. 2MB for 3-level pagetable and 4MB for > > > > > > 2-level pagetable). > > > > > > > > > > > > Further, the above booting contraint also results in memory wastage > > > > > > because if we boot kernel from some address (which is not same as > > > > > > RAM start address) then RISCV kernel will map PAGE_OFFSET virtual address > > > > > > lineraly to physical address and memory between RAM start and > > > > > > will be reserved/unusable. > > > > > > > > > > > > For example, RISCV64 kernel booted from 0x80200000 will waste 2MB of RAM > > > > > > and RISCV32 kernel booted from 0x80400000 will waste 4MB of RAM. > > > > > > > > > > > > This patch re-writes the initial pagetable setup code to allow booting > > > > > > RISV32 and RISCV64 kernel from any 4KB (i.e. PAGE_SIZE) aligned address. > > > > > > > > > > > > To achieve this: > > > > > > 1. We map kernel, dtb and only some amount of RAM (few MBs) using 4KB > > > > > > mappings in setup_vm() (called from head.S) > > > > > > 2. Once we reach paging_init() (called from setup_arch()) after > > > > > > memblock setup, we map all available memory banks using 4KB > > > > > > mappings and memblock APIs. > > > > > > > > > > I'm not really familiar with RISC-V, but my guess would be that you'd get > > > > > worse TLB performance with 4KB mappings. Not mentioning the amount of > > > > > memory required for the page table itself. > > > > > > > > I agree we will see a hit in TLB performance due to 4KB mappings. > > > > > > > > To address this we can create, 2MB (or 4MB on 32bit system) mappings > > > > whenever load_pa is aligned to it otherwise we prefer 4KB mappings. In other > > > > words, we create bigger mappings whenever possible and fallback to 4KB > > > > mappings when not possible. > > > > > > > > This way if kernel is booted from 2MB (or 4MB) aligned address then we will > > > > see good TLB performance for kernel addresses. Also, users are still free to > > > > boot Linux RISC-V kernel from any 4KB aligned address. > > > > > > > > Of course, we will have to document this as part of Linux RISC-V booting > > > > requirements under Documentation/ (which does not exist currently). > > > > > > > > > > > > > > If the only goal is to utilize the physical memory below the kernel, it > > > > > simply should not be reserved at the first place, something like: > > > > > > > > Well, our goal was two-fold: > > > > > > > > 1. We wanted to unify boot-time alignment requirements for 32bit and > > > > 64bit RISC-V systems > > > > > > Can't they both start from 4MB aligned address provided the memory below > > > the kernel can be freed? > > > > Yes, they can both start from 4MB aligned address. > > > > > > > > > 2. Save memory by allowing users to place kernel just after the runtime > > > > firmware at starting of RAM. > > > > > > If the firmware should be alive after kernel boot, it's memory is the only > > > part that should be reserved below the kernel. Otherwise, the entire region > > > - can be free. > > > > > > Using 4K pages for the swapper_pg_dir is quite a change and I'm not > > > convinced its really justified. > > > > I understand your concern about TLB performance and more page > > tables. > > > > Not just 2MB/4MB mappings, we should be able to create even 1GB > > mappings as well for good TLB performance. > > > > I suggest we should use best possible mapping size (4KB, 2MB, or > > 1GB) based on alignment of kernel load address. This way users can > > boot from any 4KB aligned address and setup_vm() will try to use > > biggest possible mapping size. > > > > For example, If the kernel load address is aligned to 2MB then we 2MB > > mappings bigger mappings and use fewer page tables. Same thing > > possible for 1GB mappings as well. > > I still don't get why it is that important to relax alignment of the kernel > load address. Provided you can use the memory below the kernel, it really > should not matter. Irrespective to constraint on kernel load address, we certainly need to allow memory below kernel to be usable but that's a separate change. Currently, the memory below kernel is ignored by early_init_dt_add_memory_arch() in drivers/of/fdt.c Regards, Anup