Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2993236ybt; Mon, 29 Jun 2020 12:20:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1W0ZrtooJAGkdoUL6MTERzfsSMXHFlv9bmliXap5iB6oXxoa8cs2OuyIwqtvU1gx4Q27/ X-Received: by 2002:a50:b2c2:: with SMTP id p60mr18745589edd.374.1593458418531; Mon, 29 Jun 2020 12:20:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593458418; cv=none; d=google.com; s=arc-20160816; b=j3IKw741btobEpWV5Y5vYxWQzyKuYP660MFoUWksh0i3xiA1VFdXj2S/iov3IFmZoG StcWj8/rEPFUSdo8Es1OJlVii4nryy2IpBS5+hE5RI0qes0IJWIxlIMdfAiTzna+kTRe spYBBjHrf58szUUprsbJkL+CwCSRIAchNW/p2w6zZHxVO5m5Hk2S6DbC5PR0w7j072Qi bjkJtVSnf3iZ+36mYpwEqXdBcunblcfTCfVC6XbGQiaC7WryT329OTy+WziA/lMI69t3 jcKGWYBikSRrriPolKLOL10LYTFA6yY917hLQ7dLRf9tKq0nakzlBA9f4JC62tLW0Jin EzSg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject; bh=L1llao+N1ItHwS5WUPVwSSBRDCeyLcOEiY8zovVfOFE=; b=hVa8qJDJ0jHHsudJhEZNO4KRTqFWmOuFkuJJ/M4ZDRUAsHlIkaZVbTdRmOt808SHLY +5b2BBqA2CfaPn3aT+J3iYLrH0EDrilh64LnD24Rf/wPUdxi2fMxr5avrGPoafm1M+R6 p31kEh7nuPz2//87fhBhv5H2vA9+pI4ks7v4aRwZ9HIWppmDk4arLtk/YQbmVOccreRD pYnB1oQs8aOcBXws2MkcvOC5228dt5awloIaN/pnKmFJM1YBhBEeVsqdIErjX98N2lI9 UCyvcDsmxSBzpyjM9b2AROB8Fb/tUCNOO27lrrl+e2Qc6yFULmgfO/ny3cx7K3GZmV/i KFMQ== 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 c15si346406ejk.329.2020.06.29.12.19.54; Mon, 29 Jun 2020 12:20:18 -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 S1729810AbgF2TTu (ORCPT + 99 others); Mon, 29 Jun 2020 15:19:50 -0400 Received: from mslow2.mail.gandi.net ([217.70.178.242]:58746 "EHLO mslow2.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732065AbgF2TTn (ORCPT ); Mon, 29 Jun 2020 15:19:43 -0400 X-Greylist: delayed 2332 seconds by postgrey-1.27 at vger.kernel.org; Mon, 29 Jun 2020 15:19:42 EDT Received: from relay10.mail.gandi.net (unknown [217.70.178.230]) by mslow2.mail.gandi.net (Postfix) with ESMTP id 09BF23A4382 for ; Mon, 29 Jun 2020 14:47:10 +0000 (UTC) Received: from [192.168.1.11] (lfbn-gre-1-325-105.w90-112.abo.wanadoo.fr [90.112.45.105]) (Authenticated sender: alex@ghiti.fr) by relay10.mail.gandi.net (Postfix) with ESMTPSA id EEEC7240007; Mon, 29 Jun 2020 14:46:47 +0000 (UTC) Subject: Re: [PATCH 0/2] PUD/PGDIR entries for linear mapping To: Paul Walmsley , Palmer Dabbelt , Anup Patel , Atish Patra , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org References: <20200603153608.30056-1-alex@ghiti.fr> From: Alex Ghiti Message-ID: <452647fc-bcfc-c47c-50eb-cb06a94f6d38@ghiti.fr> Date: Mon, 29 Jun 2020 10:46:47 -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: <20200603153608.30056-1-alex@ghiti.fr> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 6/3/20 ? 11:36 AM, Alexandre Ghiti a ?crit?: > 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(-) > The way to handle the remapping of the first 2MB is incorrect: Atish has issues while using an initrd because the initrd_start variable is defined using __va between setup_vm and setup_vm_final and then its value is inconsistent after setup_vm_final since virtual addressing was modified with the remapping of the first 2MB. I will come with another solution to this problem since the way I handle it for now is not correct. Thanks, Alex