Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp594725ybg; Wed, 3 Jun 2020 08:40:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzW7ynmwzm7lNBtnwcUyO/MZaktx63JuSEmy+Zxl1YCQ7i9vGsZuRI0NHaK08ChPNGsVHP5 X-Received: by 2002:a17:906:4a03:: with SMTP id w3mr27886033eju.154.1591198830833; Wed, 03 Jun 2020 08:40:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591198830; cv=none; d=google.com; s=arc-20160816; b=jM1F+WnjIPFclOp4N1UPFKHPnQz7w6gH54JNeM14ML8Fdnk2tbgWLUmuXfe9wLJ2JJ iS/uV7duye0o4E/TS3GJqKk3LiOPGrpOgJ+EUZ3vY4Mq1afIe9SRQJTLYQd6qLjqI6kG /uLpl3/IOKEhO3MfzE35fCVIOjvXkayTTpH2YntrbxGp1/ovYt1aagBC3eoNNVRQ7E6C eOjd4u7SjHs5sVAgBvk3TFVfs//Mg59KkCjb5oAx5S48fOzIe0UPNWWV4Co9WxlImlPT LUKVaUGtGcOu+KcDZ9aO/7zJ+ymRCQ9QCvKo2HB2lnNr+gjMKxHF7PGHKLM/JKetHHBK uCdA== 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:mime-version :message-id:date:subject:cc:to:from; bh=PkxkQAgWYCT7856H+1yGm/0POeuSOxtWg8tx411FaGk=; b=sga7AtSbp6cguzjAMMVTQ20dWQ7/NNLqswY9kAU6dgWMjoYsRgzEKWfzncLDQdDNLM MbYYOS+EbbyyxqM5egQlUJdN0bEl+yyJLGpzFPFwAnpE/yVh5Nv2NJtG3uktTf/Lbpso PdamYdGbNBCtD7c51YlSwVjvULxiPOc5alwj7/ZSC5VlCLE6azlHcUeZCOS1LF799s5u lOatQ1FZyRsxcLtUBkEKbxNnI8UFU9ZCzytV6mUs55q3++86mwyVpH2nrGUJKPfLc3A4 yWabdt1muqZ+BtKf5lXp/XokqachL99GsBjht4t9B4cjOhMoPe15OyxUxajdJac3pBEP P08A== ARC-Authentication-Results: i=1; mx.google.com; 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 j26si1276402edf.489.2020.06.03.08.40.07; Wed, 03 Jun 2020 08:40:30 -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; 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 S1726154AbgFCPgS (ORCPT + 99 others); Wed, 3 Jun 2020 11:36:18 -0400 Received: from relay9-d.mail.gandi.net ([217.70.183.199]:34971 "EHLO relay9-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725904AbgFCPgS (ORCPT ); Wed, 3 Jun 2020 11:36:18 -0400 X-Originating-IP: 90.112.45.105 Received: from debian.home (lfbn-gre-1-325-105.w90-112.abo.wanadoo.fr [90.112.45.105]) (Authenticated sender: alex@ghiti.fr) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id CE2A5FF811; Wed, 3 Jun 2020 15:36:14 +0000 (UTC) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Anup Patel , Atish Patra , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH 0/2] PUD/PGDIR entries for linear mapping Date: Wed, 3 Jun 2020 11:36:06 -0400 Message-Id: <20200603153608.30056-1-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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