Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp3918779rwl; Tue, 27 Dec 2022 18:10:14 -0800 (PST) X-Google-Smtp-Source: AMrXdXvaW6Bj2RkdmRLcbcYIgT73MgQ41Rz4eCXzeNwgR6yoqZyclbMv8H3XJrY2zGdAD3iP77RX X-Received: by 2002:a05:6a20:8346:b0:a7:8ce5:6fc6 with SMTP id z6-20020a056a20834600b000a78ce56fc6mr21906778pzc.13.1672193413771; Tue, 27 Dec 2022 18:10:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672193413; cv=none; d=google.com; s=arc-20160816; b=e4qbZEPnQliNYoK4BjSYhbZ3R6g1uOZhs0GvhPyH2ISPXCMiOqCV6g6TH4hpgHG6xd kmEQPzj6MUW4pGaXqYV2OGVlSPp1JmVqWZyCpzxQrTW2JA/DY8KaCO5TFoCZ8PwooIaz k9jKiNLc1T5UiruAF6byUHOFTH8ZEwMk08fKEoC16fPYooBeoyVao7ZRH+pJ7asbuFF5 wH7iupdrX3iB719n1WZ+JKdvauJEOZFyvm79AUxiD/TCOUeoBQvdY7pGQDlosxPlAz5M u2fpWhSAx7nxsxo+fRoEVYv7GRBpyGOONNXGAhPOAym8f0/8iyIUs1RNsPk77NhqZsyy 1uZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from:cc :references:to:content-language:subject:user-agent:mime-version:date :message-id:feedback-id:dkim-signature:dkim-signature; bh=iC1a58fopLg2dyidRFyFPZOZXaXL0ZruSKVGJ6/nOig=; b=VUA97rZTrBo5qz/ibxlhyq14fgEGKItBEyvfnnC3UYRQ/r51VLQAbWXHsonR4sgoW4 aj7XKUAq9damVzs0fNyd224SeWoJeJ2RCbq4SpBFJeJtUm38UEJwN0oOegSBasDj4YJ8 v2Lqh0Z4x4rzR+Q9Z2y9N1XyGoHdA+jpb9x9juEPE4w8WbYY4Kja5S4jXEZ+e8CiWbSq igo6w4PebD9pK6HQ0Bj8qg3/Z2CWL6LL7E+18RH9IMYzih6CEX60YGOP9OxhMcX8Z7zk 48Nr8M9M4m4RZAB9Ai9BG3hEzvdSTDmt5HVel0H4hO07bD6pIBlfZ0y39HvZwynOAcP4 v3pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sholland.org header.s=fm3 header.b=E4w5GwRQ; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=IcteJ0wE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sholland.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r24-20020a63ce58000000b00477c498cca3si15198102pgi.55.2022.12.27.18.10.04; Tue, 27 Dec 2022 18:10:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sholland.org header.s=fm3 header.b=E4w5GwRQ; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=IcteJ0wE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sholland.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231809AbiL1Bir (ORCPT + 65 others); Tue, 27 Dec 2022 20:38:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231263AbiL1Bio (ORCPT ); Tue, 27 Dec 2022 20:38:44 -0500 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66762DFB4; Tue, 27 Dec 2022 17:38:43 -0800 (PST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id D26AD5C00AE; Tue, 27 Dec 2022 20:38:42 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Tue, 27 Dec 2022 20:38:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1672191522; x= 1672277922; bh=iC1a58fopLg2dyidRFyFPZOZXaXL0ZruSKVGJ6/nOig=; b=E 4w5GwRQ+8JtzSAznWScl6ANpSNTjAR+dZdPBmXkUxKOxPUKBvBTmcTyi63N5kKT7 H1963AjYxTST5hYfg15Tu3+OOWKXIh15dyJuisJVNytsv93pnA0ZAVFN5JmiJAtn z8uPTmwonvlgkAIBOEVputB9tKYEwKmXKHgJz1vAhGYWIJYcDp3474+w62ZfXNgq T6xaC8eR3smBS/r3Y5xjSztycCyBj67yMmr1mLzR2TOMIlhi+A9ep3ZBnFiE7PwH j8+AUT1bmwH/si70iqIx0swW/vF+fYN4+ejARZD2sOofT+E380VoiArSVBObC+qN KhrYdgMFB12Z9rvw/1NAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1672191522; x= 1672277922; bh=iC1a58fopLg2dyidRFyFPZOZXaXL0ZruSKVGJ6/nOig=; b=I cteJ0wEdzCTJFIm693Mp4YyQCI8l/LyY2LVrrKKqnmlteO3PMjNrEYrZI5CTtvCF 9SWl09pJ7NnkfDGOPS8xJIyLgH95IstiYl8GJAdqgEpsUvXAsDHjKxFmtPyvJCdw foijtjsJ/i8pQsoSYHBR+/xt9la3IQKXXlSc+m42tteJeqOfBeQlf+uulfKGjtmi Oq+Ts2yQ8RSma6RI4fx5aC6n2RHG/CNolSglPQiz/Oncz8CMsgZLOyfRZd4Fsvt+ I/KaftcoNbaMjA/m9ZYon7K+xWmiWBi48/vrnGIqLxMraJ8kaJrQ0oNY/8IkTNLs 9aZasQs0C5YV83pL5LuEg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedriedugdefkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefkffggfgfuvfhfvefhjggtgfesthejredttdefjeenucfhrhhomhepufgrmhhu vghlucfjohhllhgrnhguuceoshgrmhhuvghlsehshhholhhlrghnugdrohhrgheqnecugg ftrfgrthhtvghrnhepjeegjeejteeftedvgfdtlefgveelgedugeelheeuudeigeejjeef jeelkeffvedvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepshgrmhhuvghlsehshhholhhlrghnugdrohhrgh X-ME-Proxy: Feedback-ID: i0ad843c9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 27 Dec 2022 20:38:41 -0500 (EST) Message-ID: Date: Tue, 27 Dec 2022 19:38:41 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux ppc64le; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Subject: Re: [PATCH v3] riscv: Use PUD/P4D/PGD pages for the linear mapping Content-Language: en-US To: Alexandre Ghiti , Palmer Dabbelt References: <20221213060204.27286-1-alexghiti@rivosinc.com> Cc: Paul Walmsley , Albert Ou , Guo Ren , Rob Herring , Frank Rowand , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arch@vger.kernel.org From: Samuel Holland In-Reply-To: <20221213060204.27286-1-alexghiti@rivosinc.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/13/22 00:02, Alexandre Ghiti wrote: > During the early page table creation, we used to set the mapping for > PAGE_OFFSET to the kernel load address: but the kernel load address is > always offseted by PMD_SIZE which makes it impossible to use PUD/P4D/PGD > pages as this physical address is not aligned on PUD/P4D/PGD size (whereas > PAGE_OFFSET is). > > But actually we don't have to establish this mapping (ie set va_pa_offset) > that early in the boot process because: > > - first, setup_vm installs a temporary kernel mapping and among other > things, discovers the system memory, > - then, setup_vm_final creates the final kernel mapping and takes > advantage of the discovered system memory to create the linear > mapping. > > During the first phase, we don't know the start of the system memory and > then until the second phase is finished, we can't use the linear mapping at > all and phys_to_virt/virt_to_phys translations must not be used because it > would result in a different translation from the 'real' one once the final > mapping is installed. > > So here we simply delay the initialization of va_pa_offset to after the > system memory discovery. But to make sure noone uses the linear mapping > before, we add some guard in the DEBUG_VIRTUAL config. > > Finally we can use PUD/P4D/PGD hugepages when possible, which will result > in a better TLB utilization. > > Note that we rely on the firmware to protect itself using PMP. > > Signed-off-by: Alexandre Ghiti > --- > > v3: > - Change the comment about initrd_start VA conversion so that it fits > ARM64 and RISCV64 (and others in the future if needed), as suggested > by Rob > > v2: > - Add a comment on why RISCV64 does not need to set initrd_start/end that > early in the boot process, as asked by Rob > > Note that this patch is rebased on top of: > [PATCH v1 1/1] riscv: mm: call best_map_size many times during linear-mapping > > arch/riscv/include/asm/page.h | 16 ++++++++++++++++ > arch/riscv/mm/init.c | 25 +++++++++++++++++++------ > arch/riscv/mm/physaddr.c | 16 ++++++++++++++++ > drivers/of/fdt.c | 11 ++++++----- > 4 files changed, 57 insertions(+), 11 deletions(-) This works nicely on D1! Before: MemTotal: 490680 kB after: MemTotal: 492472 kB and I tested booting with CONFIG_DEBUG_VIRTUAL without issue as well. Reviewed-by: Samuel Holland Tested-by: Samuel Holland