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: 13177604 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 011EAC6FD19 for ; Thu, 16 Mar 2023 13:17:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8DBDA900006; Thu, 16 Mar 2023 09:17:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 88B7B900002; Thu, 16 Mar 2023 09:17:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72BF1900006; Thu, 16 Mar 2023 09:17:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 621EA900002 for ; Thu, 16 Mar 2023 09:17:20 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 37735140899 for ; Thu, 16 Mar 2023 13:17:20 +0000 (UTC) X-FDA: 80574812640.12.BED39DF Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by imf17.hostedemail.com (Postfix) with ESMTP id 4624F4000A for ; Thu, 16 Mar 2023 13:17:18 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=2Ev7aL6Z; spf=pass (imf17.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.42 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678972638; a=rsa-sha256; cv=none; b=YzfDfL8s1ITPevZANRzwrBbUNWRhMYN2pHhvO+AJnNQVX62gyObddsPHRC4GefVTkGkpeQ orYC+mgyo+VkCGpQEosoj/z9/i0x8nPeiINjhZyFBScFUDENHmi6G4Jf2MUgBu53onoM2e SZ0xTYQUwXIE0zIEkQMEZykm5cDEe/U= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=2Ev7aL6Z; spf=pass (imf17.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.42 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678972638; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=yb0JNi6cRDb5cM5WC9CEwD00CUTLKwtDAX0RcxE9c8c=; b=qhhNQacNNIZ23dX9lvctWCpUdVC631RJxP3o6efj0Zl9KKsSYoVyjGAda7Wd5AmJFYPwPc 5x4/MvFz9CMRwXCg+G8PaSLwsimf19BS3BlmggVZJFLlc4HrmBGoWFoFyh3kLPqNdYWXOE 2WkGk7kpPRULGZ7+0kkg+iXZoskMYTA= Received: by mail-wm1-f42.google.com with SMTP id p13-20020a05600c358d00b003ed346d4522so1113671wmq.2 for ; Thu, 16 Mar 2023 06:17:17 -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=XAKn9WnL74kNMosHO1v/qU9Rqh/Zmq6mzmjfrDv9PUIS0zakKEXWEbcqNJBveo5jta URICr2yicrkCQ2GlKcB5I8ZkwwoNbbO9H2K3EYxfRPLY+sn9Y8zDynF5ZgWd7Rhg07+G Q4rSe+njKACJ8fA3GzygUAsE3IIjlyM/Lf/u8JKp6k7BHleIOEON2iOuERKG7IFW6XR6 OmAX6nWNk50hwuFx3wkn3h1gEMXZqFERkLgwfRGz3PUUoT36lhL8PKffhWEY1Sqzbaw0 21pcz/WQaIQmW0w6Ac3j2zMam81Yd5wJVkL26qhC0bAa83BuHQgpv+faQiV9eIGkihT+ C1+A== X-Gm-Message-State: AO0yUKV4EYj1+grgjV4TZmGq1ykOUvDKvdGDdcsSi5Eg5skwNIXR8ErF Kyk9b3+DV2Z2C6V6mO77cTWCxg== X-Google-Smtp-Source: AK7set/fhVDeuPDPVeUXVE63TtFOQa0R+UvB04ejBiBb1VAkOz3jRjT1WOxKNz9X4Jff53YqrdofPA== 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-Rspam-User: X-Rspamd-Queue-Id: 4624F4000A X-Rspamd-Server: rspam01 X-Stat-Signature: esjr7edrbg18de5zz51nts31zhsub8u8 X-HE-Tag: 1678972638-722766 X-HE-Meta: U2FsdGVkX18hMiskhcz9/GpD8EbZvKtEOeasxBVz+Uheg3WJiNu2xsg7BMqepoAwzmtSkAdUyzNwZZ5QZWyL8I/usVHOKE7xU5zccXPmOAnIlFBU+cs7qQKPy/bD7M4cRpVWNwDKDw1YUDuHGlGtFNTsxefJ8nmhOZWErBuNhpXUMUT+yCpM2+GcC2s1puYtUwLsHa7/iWplvnrPACyaVocycFlM5bP4Fdi2GE2/e4UvJl+LrPj2JBQmik/c7KDm/SIjGDZH+EHj4nit3rC7VmKzeDDPhz52910OWnZH5mqj/fXnu9cBQJeLKSLesO+frBL2htUPwwxQdWFlTqJnQnXNn0dck73wy1Tfrz1FKTcVbkeKaPiA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bR2qZY9O X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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(-)