Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp799940ybg; Wed, 10 Jun 2020 14:10:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy61xPHNql3rsrHNwYxf2VhiGrD7FbcMpGDcRB9OATBQH/HONfSQzssJsWkxD1KPft2aLzR X-Received: by 2002:aa7:d79a:: with SMTP id s26mr4233370edq.202.1591823448889; Wed, 10 Jun 2020 14:10:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591823448; cv=none; d=google.com; s=arc-20160816; b=DSu+GOyz5Qe0WSpe6MlLC66FEhOiaUE62hdqqj8mhSf2OqYql7lP8qfditEE55vudX F6H3M+aADnBzebr9NHBSc67MilX/QSeR4ey/2YUQw+6momP1oYloDh2jUzTufxmlcyfE 0Saq5+ORlCwF46R4IBlk6gzU5OS07n4CcEXciJvm+kgoD1YhKtJ2KlZXHyMGl1yJpADO 6dIQCI4L/D8BI51t1umtFqm3tMLqUebmOD6kRABVO1FFqqub9sEvjSDCJeLFLp+9gmmW y3cr4HCBADZxpm+TJ6lDqk90vlztFjsjhrp/ZPpfptdqFmX3teXiQrprIYEwYhCxzBVS AJKg== 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=cuF+cADa9Q3nUhREBOrFxHULJ1t6/1ibL+MaQiIT2O4=; b=I2m1zVcyFmdQZ8p0etPbgRXxTtF9RpmNSrtv1kKkZ1Y3BmQGK+WpAK8aMlG1J6NoJr U+VdpzFdL6mX/vR2ObnSBBU6NLyklGcP+d2zCqCKAzofp8BwZHvPwKnl6+Z33LcJ6O9r CfCHWzZe0eGNJJdLNVA6ffRAtSZDw51uBL0qutJLYyNVy1GAOGHGm+TTBlbIQRCAv0k/ YUqxg4F/sZfjIntKLrrEhrw9/zLfoBqvDexWC9gl+Be989oIvK2qO+mc3ldpc3q7W++X 49tqRNbifnDSol0r/cSME714l6ECpTiNPayr4wTRCvtlU8/LnuCq1D7tpFshisNfsJxF 31ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=ShddrI1K; 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 u20si722511ejr.41.2020.06.10.14.10.25; Wed, 10 Jun 2020 14:10:48 -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=ShddrI1K; 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 S1728988AbgFJSdA (ORCPT + 99 others); Wed, 10 Jun 2020 14:33:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728973AbgFJSc7 (ORCPT ); Wed, 10 Jun 2020 14:32:59 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B0CEC03E96B for ; Wed, 10 Jun 2020 11:32:59 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id c3so3401858wru.12 for ; Wed, 10 Jun 2020 11:32:59 -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; bh=cuF+cADa9Q3nUhREBOrFxHULJ1t6/1ibL+MaQiIT2O4=; b=ShddrI1KueMSqR6Wmvilt3rbyr+sz5HwFSfAUsjfnmYpijcnBNTyMgSkGknkRMlEvD T7ONcUqIiN6ZuI/+73WkfNKjPnjpCxAY0Tq+chqDh8IyImYw44Sg7NfS0nCQK0g2iQfF hJUycqfOB9F5s9VszPETBUbzqglDtFaWamE4I= 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=cuF+cADa9Q3nUhREBOrFxHULJ1t6/1ibL+MaQiIT2O4=; b=OSdeBr0wKEEfOAO956zGg4MgtreWcUd4xuQVUDdBYnOMkEk57Cot0ZxccAxIfs6DQI zO4J777EQElTnrbILEg8WxQ1x9GYNwR+i+oqKO0+mnY0fClzQ3/SyTY67OW6nnGKYhoJ vODmUXzHfyiTHdECISSIIQDIdy+O7IYnwJCUJ0iTlsDiQd9buNHkWnPVYviI4DtuxrMz +rgKRNWtDi771rVZGtnhxVjcWc2GZ3JkXLW1Wh+Zjn7qyhtja3ZaoqgbuNicFgpPEjMO E/UA3PhEaxyK6Tl5KbWRunhPaqC2c7UHyWWrx+nCLJRiOJXI9dYPA2NPDr5H6UFemIqg cDxw== X-Gm-Message-State: AOAM533Z3CGDG4Z9CEjFgjwg6syoW2tMu79jGtfibBC1sKmRvzGVbSF5 naxo1A6Et5Aye89YUQWvBn9+MfG66zVSIGdlUwbu X-Received: by 2002:adf:e68a:: with SMTP id r10mr5092633wrm.384.1591813978084; Wed, 10 Jun 2020 11:32:58 -0700 (PDT) MIME-Version: 1.0 References: <20200603153608.30056-1-alex@ghiti.fr> In-Reply-To: <20200603153608.30056-1-alex@ghiti.fr> From: Atish Patra Date: Wed, 10 Jun 2020 11:32:47 -0700 Message-ID: Subject: Re: [PATCH 0/2] PUD/PGDIR entries for linear mapping To: Alexandre 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" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 3, 2020 at 8:36 AM Alexandre Ghiti wrote: > > This small patchset intends to use PUD/PGDIR entries for linear mapping > 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 virtual > 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 those 2MB memory if it is not marked as reserved? > 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 some > 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 performance > 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 whenever > 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 PUD 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 PMD > 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 > > -- Regards, Atish