Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp2029601img; Sat, 23 Mar 2019 20:34:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqwU9owbaa8fvJqUElJNZ9WNNwvXx+Vi0ZkAFHuprvryV6pfZs5qQ3iH4OU9BhIp/Scp/IaD X-Received: by 2002:a17:902:2bc9:: with SMTP id l67mr17895056plb.102.1553398457425; Sat, 23 Mar 2019 20:34:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553398457; cv=none; d=google.com; s=arc-20160816; b=hmD86xA2ITBNIN/sKmEzpwvV+e4+wphF9/smHqLq7BG4gsLn9EVShdEAA7EfUMKWRy axd7t2nW6eeBGHVsp6vsYe02D4cZnaEePfTd+K0s90OXLVe8TTCliYBICrgQtxfZqMB0 WBhO6pR4k6K07gNNeouhx3NyQbHU4Y0mCacVxJtrgARJpYk+rhxv1PHEClyn7agtTgLK /QHK3hca3dAY2ZjkxO/iF+//NjBeyVYthXvklxSa0SJ2l9xGBm3aV1J4FBeC5qN8G+62 7SkBAMHl4lfdU3dN/PR8UZdr3qoXkPIGtsXcOGiXha1vi7LlGuSnpf2k/Ts8Y9R7UgKA GpXg== 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=5r5BnJmBdEeR/Dv9Ixv/XBgxXRYB+lCzjMiA1TLjrxM=; b=SCVKO9lyONnf5OsHkBv/odJvOHOqsCbqHtjEWqvLsn06kMNjzqpBHhpUiPypF8WuP4 VLJ5DcUd7VZsfJXdjv+U7YOxBK0LQusz53KGOPY7JQZ2LT1T24mf0JJbbNE7FgeBhZEs zH+BCBKMis7Ru1hm85wP5VhYoQwPQabae1Y3i+myjq8l8TjAu5ytmJI9Xa4IlFjnEOW8 HtiPrqagdfs93IVy4u7X9rfzoTBfT6ZXVPDD8FrHBaT+l7LCnuQNPnTmMNf6tOnX9m1F jE/6tfBVEXH8mKmm3+2WCeAtHWcu/qIBZ0We+a9NvO0gmOlXE70LhlmmJlPsg4M3BJeg agbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=2AllWECy; 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 s21si973632pfh.260.2019.03.23.20.34.02; Sat, 23 Mar 2019 20:34:17 -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=2AllWECy; 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 S1728052AbfCXDco (ORCPT + 99 others); Sat, 23 Mar 2019 23:32:44 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:47086 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728019AbfCXDco (ORCPT ); Sat, 23 Mar 2019 23:32:44 -0400 Received: by mail-wr1-f66.google.com with SMTP id o1so6354291wrs.13 for ; Sat, 23 Mar 2019 20:32:43 -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=5r5BnJmBdEeR/Dv9Ixv/XBgxXRYB+lCzjMiA1TLjrxM=; b=2AllWECyHNVdDWdGmXG3lZ/Yh4+CrRBHOFVG/W8CmEa/aq913z87NR6MXsFItvj4gJ PY6v0y6rpiElfAIuWXSI+EXbQ1F5aS5AwWYrekhxYKatsylJhe9DuRZZQG124crIQM7Y MLE1gfSsWSNZRedEewc3lruHi15EeaSo/lWkxp+zMN1qyKM+PddhKs462wdGueehZRRi FyhZ4mEomgfhpKJGpGfrcAP04UaNrIu12gKvgKaP6PKWeG2txus1f6SFNEG3iEmrrFic ycK02sKtwiR5QbS7gFi3QBL/w4CbJjwWNRIGt6mL+/IRwzsh//aDKVDO+X0JldoDQaPB tHpA== 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=5r5BnJmBdEeR/Dv9Ixv/XBgxXRYB+lCzjMiA1TLjrxM=; b=fKaXC/2feFQ6dcs4ZyB/vzmjHgDxfCblRFe/fkG2EjM6w7+yw4T5H0pSF5JjrjAbYy 70mqmdV5VAEAv6Zimk9jtvSbINqSfvWDoXCGSspf0AR0IEuTeQMukI2mPihjzVUz34em aGqy53yQETnIuNFAyjnEPnB0vufzbTTkUHwvqoyFpmPjcXKTfqjl8U1gLAl6w4gPbihE 74JGS+aWfZinvUf8ZJbRZgbLCPicHwS2XhSTKmyZOs9CAIaE2m6vhurq2Cm/ItQmwzak xDD7MbaRYxKGJ0z2BtGRrNGddv3sF/XHHRJNkgd63p8glOYkbqh/d9R0P/IhRQk6e9rv MIZw== X-Gm-Message-State: APjAAAW/YMmIrB+k6n83ng6EwdaMPVtgL1DcpAhZPwnhTF/yIb2MndgL TWmgmRUT/WlGD54lnKIg3diUhKVMXgsLh6P09Iy3qQ== X-Received: by 2002:adf:fe03:: with SMTP id n3mr6925904wrr.59.1553398362654; Sat, 23 Mar 2019 20:32:42 -0700 (PDT) MIME-Version: 1.0 References: <20190321094710.16552-1-anup.patel@wdc.com> <20190321094710.16552-4-anup.patel@wdc.com> <20190323154012.GA25149@rapoport-lnx> In-Reply-To: <20190323154012.GA25149@rapoport-lnx> From: Anup Patel Date: Sun, 24 Mar 2019 09:02:31 +0530 Message-ID: Subject: Re: [PATCH v2 3/5] 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 Sat, Mar 23, 2019 at 9:10 PM Mike Rapoport wrote: > > On Thu, Mar 21, 2019 at 09:47:51AM +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 add kconfig option BOOT_PAGE_ALIGNED. When it is enabled we use > > 4KB mappings in initial page table setup otherwise we use 2MB/4MB > > mappings. > > 2. We map kernel and dtb (few MBs) in setup_vm() (called from head.S) > > 3. Once we reach paging_init() (called from setup_arch()) after > > memblock setup, we map all available memory banks. > > > > With this patch in-place, the booting constraint for RISCV32 and RISCV64 > > kernel is much more relaxed when CONFIG_BOOT_PAGE_ALIGNED=y and we can > > now boot kernel very close to RAM start thereby minimizng memory wastage. > > I have no general objection, but I presume the patch will be significantly > simplified if the addition of 4K pages support will follow the removal of > the trampoline_pd_dir. > > That said, I didn't look into the details, since they will change > substantially, only some comments on the Kconfig part. > > On the high level, have you considered using large pages in setup_vm() and > the remapping everything with 4K pages in setup_vm_final()? This might > save you the whole ops-> churn. Yes, it can save the ops churn in setup_vm() but we should let setup_vm() choose best possible mapping size based on load address alignment hence it's better have common page table setup code shared between early and final page table setup which can create mapping of any size. For example, if we are booted from 1G aligned load address then setup_vm() should create 1G mapping thereby getting better performance compared to 2M mappings. Regards, Anup