Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1079663ybg; Wed, 10 Jun 2020 23:53:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy97fEy9SdFyBEh3JuZD48EtXgsF/Cs4ZyYS13Gd2OG8JSIwdBzAQfzyU+EQv6RYKHaT6bM X-Received: by 2002:aa7:d7ca:: with SMTP id e10mr5830461eds.45.1591858411773; Wed, 10 Jun 2020 23:53:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591858411; cv=none; d=google.com; s=arc-20160816; b=hVXTka3/sSvt+ygjiOc7HKsk5Cxf98+s+YBYrExNPfsTU4zRijrTUEzt2/bB+J/NzW QrikGnz6bC6hXjku16KCqP+A2K0JOUjdnLju8fMAU4tpi2XXlCjpGlwD7K8lXwwJxUYU QkogGjbjIK98jOPMTv71kXBXJNK5sqUDpEdWeLVNKNliFBLnxStS8SRqydTgTnMOS57K tskv9po6C9fBrC6NoJMzoV+Y+UGMxHScKGLHVakLrmod3Qj58J14tg1xdCmzLaxVMoMg 1BOynLRFSObA8wk9+nZoUYg/QekCe/Y+42mQkdaZycbOKFLwgt2ngM7tDgUPLvmJ8099 r5dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=tbJl5NpkttSSenveSLH9NqSabcADVzNkB1DVL4clxc8=; b=xQQiBsJCJW0magKo/3W64N1jDi2PYUCe3iIUak89P7LbO7muVCs5MoBffsy1X8ih/8 CaDql1EhHISeJsevH/RezgIdjHXJEEVjUzPSWxVtdkoiHW3+zTjJD0HRBwKNuDPvkVF/ IGsrVND5/2QBeTEHG6pfCAq7JTdtBRsmCNmpcE7FaeGXzXNTqwX9QjMq6LGFAIzW3tTM FmODLzpHMjqbFZaGwSLSf8D8WloI2viRT/nBDo9qjH02ekmIHtaeFUJxFIlOCoLVXLoZ YIf+2sLNQexgjE4IbWjeoaCtLthFHtdQLkDnLxjDAJXLsNp+8TrDFAfCAkWdWUEHQjcK OznA== 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 gu3si1539265ejb.442.2020.06.10.23.53.09; Wed, 10 Jun 2020 23:53:31 -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 S1726643AbgFKGvY (ORCPT + 99 others); Thu, 11 Jun 2020 02:51:24 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:59635 "EHLO relay4-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726573AbgFKGvW (ORCPT ); Thu, 11 Jun 2020 02:51:22 -0400 X-Originating-IP: 81.250.144.103 Received: from [10.30.1.142] (lneuilly-657-1-5-103.w81-250.abo.wanadoo.fr [81.250.144.103]) (Authenticated sender: alex@ghiti.fr) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id A5406E0007; Thu, 11 Jun 2020 06:51:18 +0000 (UTC) Subject: Re: [PATCH 0/2] PUD/PGDIR entries for linear mapping To: Atish Patra Cc: Paul Walmsley , Palmer Dabbelt , Anup Patel , Atish Patra , linux-riscv , "linux-kernel@vger.kernel.org List" References: <20200603153608.30056-1-alex@ghiti.fr> From: Alex Ghiti Message-ID: <7ad7057e-fdab-14ef-9bdb-c77ccefd208a@ghiti.fr> Date: Thu, 11 Jun 2020 02:51:18 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: fr Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Atish, Le 6/10/20 à 2:32 PM, Atish Patra a écrit : > 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? 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 :) 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 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 >> >> >