Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1480145ybg; Thu, 11 Jun 2020 10:56:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwcGXwtAR0iIAX7slXSP2aF8igWj1vF1QyzCncp8P7VIauGuShuRF27dot+f/1bOQv6s91 X-Received: by 2002:a17:906:cede:: with SMTP id si30mr9701316ejb.315.1591898173675; Thu, 11 Jun 2020 10:56:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591898173; cv=none; d=google.com; s=arc-20160816; b=AIN06V0OvCLIyxFvKmjDURsVPRhOR1k00hDPvFQE3Z280rucNZ3xmva2KnWPYrVm7r uD3JXir9XLCLPb24ujtTWhHmQ5v7RgPuc4dHWCv8ouBXNETPIRQM74PZ/q5/MUkNFcdS aZa5HibGGZaqE/JZZ6uWTC3x4xLMcIANHQN1fDLnm72F++ARmUu+OpPvMnVQRuAj/BFg Z/5ZXERHQ9CmV8SIwrRJJWEWWNJ4jcIevYfMy/1SSTvrTR+Ss6KX/4zGfeHYSGQFmk4x QT9bAbVaAmRh6SPO55QK1I4sPWP20fU0YnRJ8FSnmkJR/NwMnXiE0maJOw6IlY9LqOVq CaCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Gv2kS6G3o83f2mBPnYmMpo8TuJCcISodnEkPwPcYQnE=; b=fGNSKsjviZe/pPfxn7gBx2pURVcrFodhIcIU5p92/0H1WusHVvyJsCjjiMrSm5MfIE I7vYTIXDHU4sYPMMMkkvzKksxgIMn45v1HXI8JigyAQpjVNKkMO2B3qgqn1jgiULazUp mjm+XEIWKj8Pu/P7JdntZv3L6q/YfsrXXJ2Nc+zvOC+E5ycwbsBO/ZdaJS0ZY2CvC/v4 upzDjnT0Enm+i9SNjBYbjrAgIHPX5hRNLRzb7NLJ/jLfrGE+tUzmnOjRbuK6xlanf2kV O/2EuUmsp+JQEozh13pQcHMMPChi6NrBzsXcechfU2IcjvoQKRMOA53Fdkd+5yJsvI5u fYKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=BOrhAO2v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d15si2499933ejt.482.2020.06.11.10.55.50; Thu, 11 Jun 2020 10:56:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=BOrhAO2v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726763AbgFKR3Z (ORCPT + 99 others); Thu, 11 Jun 2020 13:29:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725782AbgFKR3Z (ORCPT ); Thu, 11 Jun 2020 13:29:25 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0CE5C03E96F for ; Thu, 11 Jun 2020 10:29:24 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id p5so6989512wrw.9 for ; Thu, 11 Jun 2020 10:29:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=Gv2kS6G3o83f2mBPnYmMpo8TuJCcISodnEkPwPcYQnE=; b=BOrhAO2vWpMDso2mx5GwRjXpyvGIn++k+1R00OaP5mChKpAlscrEZsqwuF1TYhbAV4 OoIqjEtayPMVIGwtgDZHlAL8y/gc6CxGKQ2kGcL89SMHnAN4XqG8pAJsoYHrARWHFs76 Y0j6HMJIuKh8GQpVOZQagPjv2rsu1J4B6uD6U= 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:content-transfer-encoding; bh=Gv2kS6G3o83f2mBPnYmMpo8TuJCcISodnEkPwPcYQnE=; b=cU2X0V+L9Uaqsi9GDdL7hS7Z8J2ViZ1QzDr2rQhPfJkDg8FZvb3KPLDEb97Od/JlX/ NJLq1Bp9rZIaYu4Yp3nEYD0iszizAikLwkNh8zk0XFFbXl5zP4WKPNzTe66gS175ohlV 5k7ATY7oOcF+gK8YDrZKgWaWpCRUlpnoo1tbbomXpLu63+0uufZm0g3K74WtDr+8OLyQ dyXAIOqXDBTeOnF8JFp8W7+Fz4JHv4mL1QLUbSzrbuo1xKz9iDO5+DSS3xGclo2kWfBf HPpl7LHK4guapTwxz21M3cttRzPVmslZlvUgAsCR4dAFx5OscdqfFVxXaB2+wM9wKqYm So8A== X-Gm-Message-State: AOAM530SU0iTbCarfG8Eh83g+PHY4snT20+S6vtMkiPbMSLJgN562KSq uITQVUTNu37RFNk0TXo9zuyUqJz7gbfZe8KqajEW X-Received: by 2002:adf:edc8:: with SMTP id v8mr10227082wro.176.1591896563205; Thu, 11 Jun 2020 10:29:23 -0700 (PDT) MIME-Version: 1.0 References: <20200603153608.30056-1-alex@ghiti.fr> <7ad7057e-fdab-14ef-9bdb-c77ccefd208a@ghiti.fr> In-Reply-To: <7ad7057e-fdab-14ef-9bdb-c77ccefd208a@ghiti.fr> From: Atish Patra Date: Thu, 11 Jun 2020 10:29:12 -0700 Message-ID: Subject: Re: [PATCH 0/2] PUD/PGDIR entries for linear mapping To: Alex Ghiti Cc: Paul Walmsley , Palmer Dabbelt , Anup Patel , Atish Patra , linux-riscv , "linux-kernel@vger.kernel.org List" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 10, 2020 at 11:51 PM Alex Ghiti wrote: > > Hi Atish, > > Le 6/10/20 =C3=A0 2:32 PM, Atish Patra a =C3=A9crit : > > On Wed, Jun 3, 2020 at 8:36 AM Alexandre Ghiti wrote: > >> This small patchset intends to use PUD/PGDIR entries for linear mappin= g > >> in order to better utilize TLB. > >> > >> At the moment, only PMD entries can be used since on common platforms > >> (qemu/unleashed), the kernel is loaded at DRAM + 2MB which dealigns vi= rtual > >> and physical addresses and then prevents the use of PUD/PGDIR entries. > >> So the kernel must be able to get those 2MB for PAGE_OFFSET to map the > >> beginning of the DRAM: this is achieved in patch 1. > >> > > I don't have in depth knowledge of how mm code works so this question > > may be a completely > > stupid one :). Just for my understanding, > > As per my understanding, kernel will map those 2MB of memory but never = use it. > > How does the kernel ensure that it doesn't allocate any memory from tho= se 2MB > > memory if it is not marked as reserved? > > Yes, a 1GB hugepage will cover those 2MB: I rely on the previous boot > stage to mark this region > as reserved if there is something there (like opensbi). Otherwise, the > kernel will indeed try to > allocate memory from there :) > In that case, this patch mandates that the firmware region has to be mark "reserved" the device tree so that the Linux kernel doesn't try to allocate memory from there. OpenSBI is already doing it from v0.7. Thus, any user using latest OpenSBI can leverage this patch for a better TLB utilization. However, legacy previous boot stages(BBL) do not reserve this area via DT which may result in an unexpected crash. I am not sure how many developers still use BBL though. Few general suggestions to tackle this problem: 1. This mandatory requirement should be added to the booting document so that any other SBI implementation is also aware of it. 2. You may have to move the patch1 to a separate config so that any users of legacy boot stages can disable this feature. > Alex > > > >> But furthermore, at the moment, the firmware (opensbi) explicitly asks= the > >> kernel not to map the region it occupies, which is on those common > >> platforms at the very beginning of the DRAM and then it also dealigns > >> virtual and physical addresses. I proposed a patch here: > >> > >> https://github.com/riscv/opensbi/pull/167 > >> > >> that removes this 'constraint' but *not* all the time as it offers som= e > >> kind of protection in case PMP is not available. So sometimes, we may > >> have a part of the memory below the kernel that is removed creating a > >> misalignment between virtual and physical addresses. So for performanc= e > >> reasons, we must at least make sure that PMD entries can be used: that > >> is guaranteed by patch 1 too. > >> > >> Finally the second patch simply improves best_map_size so that wheneve= r > >> possible, PUD/PGDIR entries are used. > >> > >> Below is the kernel page table without this patch on a 6G platform: > >> > >> ---[ Linear mapping ]--- > >> 0xffffc00000000000-0xffffc00176e00000 0x0000000080200000 5998M PMD = D A . . . W R V > >> > >> And with this patchset + opensbi patch: > >> > >> ---[ Linear mapping ]--- > >> 0xffffc00000000000-0xffffc00140000000 0x0000000080000000 5G PU= D D A . . . W R V > >> 0xffffc00140000000-0xffffc00177000000 0x00000001c0000000 880M PMD = D A . . . W R V > >> > >> Alexandre Ghiti (2): > >> riscv: Get memory below load_pa while ensuring linear mapping is PM= D > >> aligned > >> riscv: Use PUD/PGDIR entries for linear mapping when possible > >> > >> arch/riscv/include/asm/page.h | 8 ++++ > >> arch/riscv/mm/init.c | 69 +++++++++++++++++++++++++++++----= -- > >> 2 files changed, 65 insertions(+), 12 deletions(-) > >> > >> -- > >> 2.20.1 > >> > >> > > --=20 Regards, Atish