Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp8648852rwb; Tue, 13 Dec 2022 08:47:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf76c+JZoYsSwQxaaBMOc7Cw1u0uwfC0lRF0ghWVAm7SqLfnvN/NyxSAdjRhNzclDmZsfopL X-Received: by 2002:a62:ab19:0:b0:576:1078:5abf with SMTP id p25-20020a62ab19000000b0057610785abfmr21823724pff.6.1670950056823; Tue, 13 Dec 2022 08:47:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670950056; cv=none; d=google.com; s=arc-20160816; b=wT4jTQOVErbjpkGpLbIbtPIJsRMdtkmIgNygcSFhxQivajc4vljS76k1zkGcR1T/DH Sr8qqEKL7fuCjDL6H1kdcT9X9BSeZ4zlu1y3s4BqHFh3BnO6lEUGBIo6rjAgCKae02xY I6V1o5/WNrejDVKrYUkZZA/wjtoyvnlLp1CWxUZ3KnTcNGBluqd9hdP0exErX40aaeCz HR+TeH8mspUxpveLCMfcZG7K5InrLyLbQdDvhog1E0cFAR8/bfqN4nJ3CYqCCEG4OTH9 uSOuZA2YMsz9Q7+XM4y3mq3KImjAwz8IPKdObnxOf6k7ejCZTpzOZ6IgQfE8HpctsZc6 iuvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=ZjI88ca8YV9FnmaROJGLMTJcQPCidHIJLaiq64mk2fw=; b=eknGNgLltcjy8fVkdBJ9w3kSm0MwTjkTbOS3QNcDJ0KOv95J9ofCZImD4628jMzJA9 /824eaA4ZHjBb5TKFIFY2tePignOLdTDhZSVanCrjp+P3PDDn0uq5wA7n076LjI+y4MF 91DcRDLh9jQ8xXrGeqFGufRzAg/vokWJvTpuWi87z1qhafeYv6H2V1d7lSm++jDjaRj5 8rtHF7/zFUrmllaLCDRccEwJi0POvJt5LI+UBVuJFcyfDpkTjjKmXDmErltM4HeWKa8c 9ubyFmg07y20dII7SY0Qd/QnDTN8iGJ9Qxw1OgPqWpJnu/nmLNkSJ1J2llNORpKbq+AZ q4BA== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cn15-20020a056a00340f00b0056bf15d0cbfsi12337699pfb.308.2022.12.13.08.47.27; Tue, 13 Dec 2022 08:47:36 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236090AbiLMQiW (ORCPT + 72 others); Tue, 13 Dec 2022 11:38:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236142AbiLMQiM (ORCPT ); Tue, 13 Dec 2022 11:38:12 -0500 Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60EDBB1C1; Tue, 13 Dec 2022 08:38:11 -0800 (PST) Received: by mail-ot1-f43.google.com with SMTP id v19-20020a9d5a13000000b0066e82a3872dso179821oth.5; Tue, 13 Dec 2022 08:38:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ZjI88ca8YV9FnmaROJGLMTJcQPCidHIJLaiq64mk2fw=; b=m3Jb7Ck9qvL2P7CZfRH2ZpZswqxc1pN4FPSIBihVQ7AD2pxIhbmjHgw+8tynuXCsxi cMuSxki1r9yMBLNnVhGyv3IlNObYlqNPfgBhwUAa2nNi8Gsu56Zd6rWoQlD+A4pb0uJl VJQ7O8KuPmLK198CExWxKqDhHHuk/wWYU4w+NyL8spHZDZyfkUtX9DXwjptdJKB3Mdhu uDOAV5H2IyQp+sso/sxrK2ByDlHNfd2o3/YKa9kNo+x+Sr+S16wosdlRJIXSP//WG1p/ MgaBuiV0NDr5pEw+dN7cQs53I2q/IO1/5eL6CCX9xQc6FUkwrPmFNn+wHYyHG88dU8Sc Ep4w== X-Gm-Message-State: ANoB5plQ6q9qKn/KJ2u7CBo1/M9jlUj6vfXNZqSmaeAACNq6ROpuscQ7 cLnVOgSwT9n+b5hlntgr87wxnaFtlw== X-Received: by 2002:a9d:6006:0:b0:670:6246:8106 with SMTP id h6-20020a9d6006000000b0067062468106mr10467047otj.4.1670949490580; Tue, 13 Dec 2022 08:38:10 -0800 (PST) Received: from robh_at_kernel.org (66-90-144-107.dyn.grandenetworks.net. [66.90.144.107]) by smtp.gmail.com with ESMTPSA id y6-20020a056830208600b0066ea5d4f349sm1361066otq.18.2022.12.13.08.38.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Dec 2022 08:38:10 -0800 (PST) Received: (nullmailer pid 2018850 invoked by uid 1000); Tue, 13 Dec 2022 16:38:09 -0000 Date: Tue, 13 Dec 2022 10:38:09 -0600 From: Rob Herring To: Alexandre Ghiti Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Guo Ren , Frank Rowand , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arch@vger.kernel.org Subject: Re: [PATCH v3] riscv: Use PUD/P4D/PGD pages for the linear mapping Message-ID: <20221213163809.GA2016314-robh@kernel.org> References: <20221213060204.27286-1-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221213060204.27286-1-alexghiti@rivosinc.com> X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no 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 Tue, Dec 13, 2022 at 07:02:04AM +0100, 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 ++++++----- Acked-by: Rob Herring # DT bits > 4 files changed, 57 insertions(+), 11 deletions(-)