From patchwork Thu Mar 16 13:17:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 6754 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp482548wrt; Thu, 16 Mar 2023 06:29:26 -0700 (PDT) X-Google-Smtp-Source: AK7set8wLlhquk4BCeXG5dG6i5B0JwuXDGxofD593e1+2RvFTuLhuH6rI189SjW3POZgJndvuNtj X-Received: by 2002:a17:903:186:b0:19e:6d83:8277 with SMTP id z6-20020a170903018600b0019e6d838277mr3794876plg.51.1678973366004; Thu, 16 Mar 2023 06:29:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678973365; cv=none; d=google.com; s=arc-20160816; b=JN65/kPYEJGFdOBdwvl+z1gOAvy/jA5uTQ7BBrpS8cAzvnQda4hbxrcW6T2wZ3TcHU HGCpuQQGE7bKxXVKsc/Xev8BUeyYQu8aDu3X4I+N+XbzBZlnAj7jivPOfHXM7Qp3n+O8 +I7zrHtRABOKWEPKVkatYZ8EVjMBzaU3sLzDXLmaE/KRQDehTNX8vzzYymY0cIDQmxak wYTC776GTDFa0Ke04xLnqInhat4amnI/cofkDGoOsltzV5sUl7TVvV1pwnCJjv6lyeoz MOLpNNZGBeqPnXu9rMRFuSLp71wi0FicPT5jlPM1zJQKDXDg3G8FTZzaWKHAOxHKfpNB 9p6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=yb0JNi6cRDb5cM5WC9CEwD00CUTLKwtDAX0RcxE9c8c=; b=YFd6TXcYFxnNr0LPnOTgKm619hH3OYnrpqtc13iXsg69NOkQVv/gTzsHYaoFZSIDX2 KTKMb+p4p1VAnEs8pisBpHwgA6/gZJIk0Gv5Czj9nPSeXwKHOqKSnYsxgVE3bMBGDs8A mts6xSGZNBMKdP7fitGs34L9x+mh4qo3+dsz5s7x2Pb/eZhEZu/anWPCpGeBWe0P8C9z nS3EJZkshGyBopEe84PqcbaOgoiYvU2L/HX6haMOfFkl9FgmdkHUMtm1STcNT31XNEbP 6AMwOEiQsZrCEzCJHdtQ7bqgsUAz3m93FrAXIKWsGKpmLaa67qJ1UgK7grpAfCqQl+39 zYxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=2Ev7aL6Z; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b2-20020a170903228200b0019e88453482si439940plh.306.2023.03.16.06.29.13; Thu, 16 Mar 2023 06:29:25 -0700 (PDT) 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=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=2Ev7aL6Z; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230252AbjCPNSF (ORCPT + 99 others); Thu, 16 Mar 2023 09:18:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230098AbjCPNRr (ORCPT ); Thu, 16 Mar 2023 09:17:47 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B23D4CC30F for ; Thu, 16 Mar 2023 06:17:18 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id fm20-20020a05600c0c1400b003ead37e6588so3143343wmb.5 for ; Thu, 16 Mar 2023 06:17:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; t=1678972636; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=yb0JNi6cRDb5cM5WC9CEwD00CUTLKwtDAX0RcxE9c8c=; b=2Ev7aL6Z6zhWHuGqPE5WRugL+grtCgf1Rw+DE5yPncJqWsJZHaCBhlqpfyHHzrwI1D IUpoT5Oj2+AxeGLsJn0E0MGbjKM4v8gxIxDStGUIXy02nc+EgqABDoYG/hOTYXCiYSOG iJXRweRTFhgYGpwr8xQprpP8UgTS76aclNF9Q88Vn0eLPUVtmLtJpd6cV7LoVTHbBvrh 1q5XhWPVPnaXpKPzJ2vWiPfcyS8XnUsHIEUE5rYpgUMCG70N6PMSUo4+vx3GXuGIPvt/ V4QCyObIV+J3zkqwYafQgaQwhM6mcbbbhcaBTGh3Ec5hqKIhtCwzq3Y8iM8EHnAJ0VUh gAdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678972636; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yb0JNi6cRDb5cM5WC9CEwD00CUTLKwtDAX0RcxE9c8c=; b=WbsvDofOg6mkjiKPWURz18FSdBiZtfTuZpTLa7iS+WjNr+HZJ4mpA8QDm+I69e/NUW 2qovvAoAfJMGpAAjCoaeQ+dL67gO+FM+F1nejQR9yu8lUkB2WgtGBWZ8P/sAWoiAjm9l 0iNeuf1SO0IqyDKEbuTdwnpqaNl3hbaz03eiA2JPH+ljirFk2rscyKKraIHXlueyn9Bo qfcl6LJq/8qugzaDbx2TNNMMsGrhhGqcI+eesOgbTzt5y9K9NOQsZH3yN6wfq0B8Txz+ s4EjSPP5+E2T7fdEWiso1fwACPYG0aZTVmi1vukc5NS20vbQQJ2UVPnAXf37B287nIkF P3Ew== X-Gm-Message-State: AO0yUKUmK3gb0R1DCqiMLMmu21qc/ydEWKJ3xNtUjZnWIC7xugDtGtIH BLWBbSB5XBp+Hm41w6M4vRa0ww== X-Received: by 2002:a7b:ca41:0:b0:3ea:f75d:4626 with SMTP id m1-20020a7bca41000000b003eaf75d4626mr21011181wml.38.1678972636633; Thu, 16 Mar 2023 06:17:16 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com (238.174.185.81.rev.sfr.net. [81.185.174.238]) by smtp.gmail.com with ESMTPSA id a6-20020a1cf006000000b003ed4f6c6234sm1963364wmb.23.2023.03.16.06.17.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 06:17:16 -0700 (PDT) From: Alexandre Ghiti To: Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , Rob Herring , Frank Rowand , Mike Rapoport , Andrew Morton , Anup Patel , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-mm@kvack.org Cc: Alexandre Ghiti Subject: [PATCH v8 0/4] riscv: Use PUD/P4D/PGD pages for the linear mapping Date: Thu, 16 Mar 2023 14:17:07 +0100 Message-Id: <20230316131711.1284451-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760531176129429604?= X-GMAIL-MSGID: =?utf-8?q?1760531176129429604?= This patchset intends to improve tlb utilization by using hugepages for the linear mapping. As reported by Anup in v6, when STRICT_KERNEL_RWX is enabled, we must take care of isolating the kernel text and rodata so that they are not mapped with a PUD mapping which would then assign wrong permissions to the whole region: it is achieved by introducing a new memblock API. Another patch makes use of this new API in arm64 which used some sort of hack to solve this issue: it was built/boot tested successfully. base-commit-tag: v6.3-rc1 v8: - Fix rv32, as reported by Anup - Do not modify memblock_isolate_range and fixes comment, as suggested by Mike - Use the new memblock API for crash kernel too in arm64, as suggested by Andrew - Fix arm64 double mapping (which to me did not work in v7), but ends up not being pretty at all, will wait for comments from arm64 reviewers, but this patch can easily be dropped if they do not want it. v7: - Fix Anup bug report by introducing memblock_isolate_memory which allows us to split the memblock mappings and then avoid to map the the PUD which contains the kernel as read only - Add a patch to arm64 to use this newly introduced API v6: - quiet LLVM warning by casting phys_ram_base into an unsigned long v5: - Fix nommu builds by getting rid of riscv_pfn_base in patch 1, thanks Conor - Add RB from Andrew v4: - Rebase on top of v6.2-rc3, as noted by Conor - Add Acked-by Rob 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 Alexandre Ghiti (4): riscv: Get rid of riscv_pfn_base variable mm: Introduce memblock_isolate_memory arm64: Make use of memblock_isolate_memory for the linear mapping riscv: Use PUD/P4D/PGD pages for the linear mapping arch/arm64/mm/mmu.c | 25 +++++++++++------ arch/riscv/include/asm/page.h | 19 +++++++++++-- arch/riscv/mm/init.c | 53 ++++++++++++++++++++++++++++------- arch/riscv/mm/physaddr.c | 16 +++++++++++ drivers/of/fdt.c | 11 ++++---- include/linux/memblock.h | 1 + mm/memblock.c | 20 +++++++++++++ 7 files changed, 119 insertions(+), 26 deletions(-)